【发布时间】:2014-04-06 19:26:17
【问题描述】:
我无法调试我的一些代码。它目前是一个简单的笔记商店应用程序,它试图在后台将字符串存储到文件中。但是当我在我的平板电脑上运行应用程序时,我得到确认代码运行的 toast,但我无法在平板电脑内部存储中找到该文件以证明它已存储?
我的代码:
public void onClick(View v) {
//Gets the note detail from the fields.
noteContent = content.getText().toString();
noteTitle = title.getText().toString();
Date date = new Date();
if (noteContent.length() == 0 || noteTitle.length() == 0) {
Toast.makeText(getApplicationContext(), "Please fill in both note title and content before saving",
Toast.LENGTH_LONG).show();
} else {
//Adds the notes together as an object of note.
note createdNote = new note(noteContent, noteTitle);
//Adds the note to the object array.
noteArray.add(createdNote);
//Testing
note test = noteArray.get(0);
String testTitle = test.getTitle();
String testContent = test.getContent();
System.out.println(testTitle);
System.out.println(testContent);
//Concatenating string.
String noteString = testTitle + "-" + testContent;
try {
FileOutputStream FO = openFileOutput(fileName, MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(FO);
try {
System.out.println(noteString);
osw.write(noteString);
osw.flush();
osw.close();
Toast.makeText(getBaseContext(), "NOTE_SAVED", Toast.LENGTH_LONG).show();
} catch(IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
我还包括读/写权限:s
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
【问题讨论】: