現在、これは私のコードです:
private void writeToSDFile(){
File root = android.os.Environment.getExternalStorageDirectory();
File dir = new File (root.getAbsolutePath() + "/download");
dir.mkdirs();
File file = new File(dir, "myData.txt");
try {
FileOutputStream f = new FileOutputStream(file);
PrintWriter pw = new PrintWriter(f);
pw.println(d8 + d7 + ":" + d6 + d5 + ":" + d4 + d3 + ":" + d2 + d1);
pw.flush();
pw.close();
f.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.i(TAG, "******* File not found. Did you" +
" add a WRITE_EXTERNAL_STORAGE permission to the manifest?");
} catch (IOException e) {
e.printStackTrace();
}
}
基本的に、存在しない場合にのみファイル/ディレクトリを作成する方法があるかどうか(おそらくifステートメントを使用して)知りたいです。現時点では、 writetoSDCard() が呼び出されるたびに両方を再作成します。
私がやりたいのは、ファイルの最後にデータを追加し続けることだけです。参考までに、次のように保存されます: 00:00:00:00
ありがとう :)
また、私がここにいる間、簡単な質問ですが、プログラムが txt ドキュメントから 2 桁の数字のリストを読み取り、それらを加算する方法はありますか? 例: 20 20 30 画面上の結果は 70 ですか? 私は本当にこのようなものを見つけていません:/