嘗試在特定目錄中創建文件,但它顯示錯誤FileNotFound。爲什麼? 我使用不可能的路徑嗎?我真的不知道,但似乎代碼應該工作。在指定目錄中創建文件
String day=/1;
String zn="/zn";
File_name=zn
String root= Environment.getExternalStorageDirectory().toString();
File_path=root+day;
File file1 = new File(File_path,File_name);
file1.mkdirs();
if(!file1.exists()) {
try {
file1.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
OutputStream fos= new FileOutputStream(file1);
String l,d,p;
l = lessnum.getText().toString();
d = desc.getText().toString();
p = place.getText().toString();
fos.write(l.getBytes());
fos.write(d.getBytes());
fos.write(p.getBytes());
fos.close();
是,也可以添加與它的文件夾路徑,如果文件夾已經退出 –
看到我的編輯答案 –
所以如果我所有的路徑是2 strigs像 dirName =根+我應該把這裏:File.separator +天; – CVS