在我试图写入文件的模拟器中:
/mnt/sdcard/Android/data/com.Me.MyApp/files/myFile.txt
我在Manifest中设置了外部写权限,但我一直收到一个找不到文件的异常。模拟器配置为具有SD卡。
为什么会这样?
InputStream is = c.getResources().openRawResource(R.raw.my_raw_file);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is));
try
{
while (zis.getNextEntry() != null)
{
File destFile = new File(destinationPath);
// EXCEPTION THROWN NEXT LINE!
OutputStream os = new FileOutputStream(destFile);
byte[] buffer = new byte[BUF_SIZE];
int count;
while ((count = zis.read(buffer)) != -1)
{
os.write(buffer, 0, count);
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
try
{
zis.close();
}
catch (IOException e)
{
e.printStackTrace();
}
答案 0 :(得分:3)
尝试以下代码
String path = "/mnt/sdcard/Android/data/com.Me.MyApp/files";
File mFile = new File(path);
mFile.mkdirs();
答案 1 :(得分:1)
Nammari的回答加上:
Android教程:在仿真器中创建和使用SD卡
http://www.streamhead.com/android-tutorial-sd-card/