2
我試圖保存外部存儲上的文本文件中的int值。當我嘗試使用saveAudio()函數時,我得到一個FileNotFoundException。我究竟做錯了什麼?我在android模擬器中運行程序。Android:DataInputStream和DataOutputstream沒有看到我的目錄
File externalStorageDir = new File (Environment.getExternalStorageDirectory().getAbsoluteFile(),"audiosettings.txt");
/**Stores the game volume level*/
int gameVolume_level;
/**Stores the music volume level*/
int musicVolume_level;
/**Stores the GUI volume level*/
int guiVolume_level;
private void loadAudio() {
try {
DataInputStream dis = new DataInputStream(new FileInputStream(externalStorageDir));
gameVolume_level = dis.readInt();
dis.readChar();
musicVolume_level = dis.readInt();
dis.readChar();
guiVolume_level = dis.readInt();
dis.readChar();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void saveAudio() {
DataOutputStream dos;
try {
dos = new DataOutputStream(new FileOutputStream(externalStorageDir));
dos.writeInt(gameVolume_level);
dos.writeChar('\t');
dos.writeInt(musicVolume_level);
dos.writeChar('\t');
dos.writeInt(guiVolume_level);
dos.writeChar('\n');
dos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
謝謝,使用權限是我需要能夠保存的。現在正在工作。謝謝! – iamarnold 2012-02-23 16:05:52