1 在<uses-sdk…/>下面添加permission
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
2 在onCreate函数的下面添加如下代码:
//写SD中的文件
public void writeFileSdcardFile(String fileName,byte [] bytes) throws IOException
{
try
{
FileOutputStream fout = new FileOutputStream(fileName);
fout.write(bytes);
fout.close();
}
catch(Exception e)
{
e.printStackTrace();
}
} //读SD中的文件
public void readFileSdcardFile(String fileName, byte [] bytes) throws IOException
{
try
{
FileInputStream fin = new FileInputStream(fileName);
fin.read(bytes);
fin.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
3 调用处:
byte [] buffer = new byte[width*height]; try //读文件
{
readFileSdcardFile("/mnt/sdcard/2.raw", buffer);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} //your program... byte[] arraydst2 = new byte [width*height];
try //写文件
{
writeFileSdcardFile("/mnt/sdcard/2out.raw",arraydst2);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
4 主要参考:
http://blog.csdn.net/ztp800201/article/details/7322110