以下のコードを使用して、ファイルを SD カードに書き込み、その内容を読み取ります。
try {
if (root.canWrite())
{
File rootdir = Environment.getExternalStorageDirectory();
File yourFile = new File(rootdir, "tomato50.txt");
FileWriter filewriter = new FileWriter(file,true);
BufferedWriter out = new BufferedWriter(filewriter);
for (int k=0; k<assignArr.size(); k++)
{
out.write(assignArr.get(k) + "\n");
Toast.makeText(MainActivity.this, "out: " + assignArr.get(k), Toast.LENGTH_LONG).show();
}
out.close();
}
} catch (IOException e) {
Log.e("TAG", "Could not write file " + e.getMessage());
try {
File rootdir = Environment.getExternalStorageDirectory();
File yourFile = new File(rootdir, "tomato50.txt");
FileReader filereader = new FileReader(yourFile);
BufferedReader br = new BufferedReader(filereader);
String line;
while((line = br.readLine()) != null)
{
assignArrBe.add(line);
Toast.makeText(MainActivity.this, "Read from file: " + line, Toast.LENGTH_LONG).show();
}
br.close();
}
catch (IOException e)
{
e.printStackTrace();
}
質問: どうすれば電話のメモリに書き込み、そこから読み取ることができますか?