档案文件=新的文件(文件名)"哪里文件开始使用&QUOT得救。在Android中 [英] Where does the file get saved using "File file = new file(filename)" in Android
问题描述
我写一个Android应用程序。在 MainActivity.java ,我创建了写,然后从文件中读取内容的方法。这些code运行成功我,可以将数据存储在一个名为的abc.txt文件,但我找不到ES文件浏览器的书面文件。
公共无效writeInIt(查看视图){
尝试{
字符串消息= editText.getText()的toString()。
最后myfile文件=新的文件(的abc.txt);
如果(!myFile.exists()){myFile.createNewFile(); } FileOutputStream中的OutputStream =新的FileOutputStream(MYFILE); outputStream.write(Message.getBytes());
outputStream.close(); editText.setText();
Toast.makeText(getApplicationContext(),信息已保存,Toast.LENGTH_LONG).show(); }赶上(IOException异常五){
e.printStackTrace();
}
}
它在哪里保存文件?为什么我不能搜索它通过文件管理器?
裁判 http://developer.android.com/reference/java/io/ File.html ,如果我包括路径,它肯定会在这条道路的位置存放。但是,如果我不能找到该目录,它仍然可以存储在设备,但哪里的文件确实保存?
文件文件=新的文件(文件名)
块引用>这code不保存任何东西,它只是cretes文件或董事路径的类包装。实际创建文件最接近的方法是使用
file.createNewFile
方法。有导游是从谷歌写入文件:保存文件
以下code产生异常打开失败:EROFS(只读文件系统)
文件F1 =新的文件(test12.txt);
尝试{
fl.createNewFile();
}赶上(IOException异常五){
e.printStackTrace();
}I am writing an android application. In the MainActivity.java, I created a method to write and then read contents from a file. These code runs successfully I and can store the data in a file named abc.txt, but I cannot find the written file in ES File Explorer.
public void writeInIt(View view) { try { String Message = editText.getText().toString(); final File myFile = new File("abc.txt"); if (!myFile.exists()) {myFile.createNewFile(); } FileOutputStream outputStream = new FileOutputStream(myFile); outputStream.write(Message.getBytes()); outputStream.close(); editText.setText(""); Toast.makeText(getApplicationContext(), "Message Saved", Toast.LENGTH_LONG).show(); } catch (IOException e) { e.printStackTrace(); } }
Where does it save the file? Why I can't I search it through the File Explorer? Ref to "http://developer.android.com/reference/java/io/File.html", if i include path, it will definitely store in that path location. However, if I not locate the dir, it can still store in device, but where does the file actually save???
解决方案"File file = new file(filename)"
this code does not save anything, it only cretes a class wrapper for file or director path. The closest method to actually create file would be to use
file.createNewFile
method.There is guide for writing files from google: Saving Files
[edit]
following code generates exception "open failed: EROFS (Read-only file system)":
File fl = new File("test12.txt"); try { fl.createNewFile(); } catch (IOException e) { e.printStackTrace(); }
这篇关于档案文件=新的文件(文件名)"哪里文件开始使用&QUOT得救。在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!