これは達成するのが非常に難しいタスクではないと考えており、HTC Desire で管理しましたが、何らかの理由で Android アプリケーションで Samsung Galaxy S SD カードから読み取ることができません。
私が使う :
public String writeFile1(String text) {
File sdDir = Environment.getExternalStorageDirectory();
File myFile = new File(sdDir+"/TextFiles/patientDetails.txt");
try{
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter =
new OutputStreamWriter(fOut);
myOutWriter.write(text);
myOutWriter.close();
fOut.close();
return "success";
}catch (IOException e){
e.printStackTrace();
return "fail";
}
}
これはうまくいきます!ファイルの内容が保存され、とても満足しています。ただし、を使用して逆を行うと...
//
File f = new File(Environment.getExternalStorageDirectory()+fileName);
FileInputStream fileIS = new FileInputStream(f);
BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS));
String readString = new String();
//just reading each line and pass it on the debugger
String s = "";
while((readString = buf.readLine())!= null){
s+=readString;
}
return s;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
ファイルが見つからないという例外が発生しました。書き込んだばかりで、SD カードをマウントすると、書き込んだ内容を確認できます。
誰かがこれに対する解決策を知っていますか? ありがとう