我迷路了。我可以访问我用USB创建的文件吗
我透过这个(剥离)代码文件:
File dir = getBaseContext().getDir(dirPath, MODE_WORLD_WRITEABLE);
try {
File file = new File(dir, fileName);
FileOutputStream fous = new FileOutputStream(file);
fous.write(data);
fous.flush();
fous.close();
long l = file.length();
Log.i("PpCameraActivity", "File size : " + l);
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getBaseContext(), "Error while trying to write photo file", Toast.LENGTH_LONG).show();
}
我可以用logcat的,我的文件似乎是创建验证(它有一个不为空lenght)。但是当我将我的android设备连接到我的电脑时,我看不到它。 那么...我的文件在哪里?它隐藏了吗?擦掉了?
编辑:我现在想要的SD卡写具体而言,使用此:
File root = Environment.getExternalStorageDirectory();
File jpegFile = new File(root.getAbsolutePath() + "/myApplication/" + filePath);
try {
jpegFile.mkdirs();
FileOutputStream fous = new FileOutputStream(jpegFile);
fous.write(data);
fous.flush();
fous.close();
Log.i("PpCameraActivity", "File written : " + jpegFile.getAbsolutePath());
Toast.makeText(getBaseContext(), "File written : " + jpegFile.getAbsolutePath(), Toast.LENGTH_LONG).show();
long l = jpegFile.length();
Log.i("PpCameraActivity", "File size : " + l);
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getBaseContext(), "Error while trying to write photo file", Toast.LENGTH_LONG).show();
}
,但我得到的FileOutputStream中创建一个FileNotFoundException异常...
'dirPath'包含什么? – 2010-02-04 22:03:28
也许是我的新目录不是在SD卡上创建的?如果是这样,我该如何选择在SD卡上创建一个目录? – 2010-02-04 22:08:24
看来我应该可以在SDcard中使用 获得的文件写入文件的根= Environment.getExternalStorageDirectory() 但是,当我尝试写我得到一个FileNotFoundException ... – 2010-02-04 22:24:52