【发布时间】:2012-12-25 13:34:30
【问题描述】:
我正在为 Android 编写我的小应用程序。我正在尝试创建文件。这是一个代码sn-p:
final String TESTSTRING = new String("Hello Android");
FileOutputStream fOut = openFileOutput("samplefile.txt",Context.MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
osw.write(TESTSTRING);
osw.flush();
osw.close();
FileInputStream fIn = openFileInput("samplefile.txt");
InputStreamReader isr = new InputStreamReader(fIn);
char[] inputBuffer = new char[TESTSTRING.length()];
isr.read(inputBuffer);
String readString = new String(inputBuffer);
boolean isTheSame = TESTSTRING.equals(readString);
if(isTheSame) {
TextView mLat=(TextView) findViewById(R.id.textView1);
mLat.setText(String.valueOf(isTheSame));
}
我无法使用文件管理器找到这个创建的 samplefile.txt。 谁能告诉我app在哪里写的路径?
好的,现在我有了这个:
String pathToExternalStorage = Environment.getExternalStorageDirectory().toString();
File appDirectory = new File(pathToExternalStorage + "/" + "testowa", "new_file.txt");
try{
OutputStream os = new FileOutputStream(appDirectory);
os.write(pathToExternalStorage.getBytes());
os.flush();
os.close();
}
catch(IOException e)
{
}
OutputStream os = new FileOutputStream(appDirectory) 抛出异常; 找不到原因。 我修改了具有权限的清单
【问题讨论】: