我想从我的应用程序内部创建一个文件夹。在文件夹中,我只想创建一个文件(比如recents),应用程序将在每次启动时逐行写入数据。
private void saveForRecents(String phoneNumber) {
//Need to open File and write the phonenumbers that has been passed into it
try{
File mydir = getDir("recents", 0);
//Creating an internal dir;
File fileWithinMyDir = new File(mydir, "recents");
//Getting a file within the dir.
FileWriter fw = new FileWriter(fileWithinMyDir.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(phoneNumber);
bw.newLine();
bw.flush();
bw.close();
}catch(Exception e){
Toast.makeText(getApplicationContext(), "Failed to write into the file", Toast.LENGTH_LONG).show();
}
}
如何访问我的目录mydir中的最新文件的内容?我想在逐行写入数据时逐行访问数据。如果有人花时间向我解释如何做,我将非常感激,因为我需要学习它。如果我做错了什么,请告诉我。