尝试在特定目录中创建文件,但它显示错误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