我正在为 Android 编写我的小应用程序。我正在尝试创建文件。这是一个代码片段:
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。谁能告诉我应用程序正在编写的路径?
好的,现在我有这个:
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) 上引发异常;找不到原因。我修改了具有权限的清单