Androidアプリを仕事のために、開発中で、クラウドのGoogle ドライブのファイルを編集したくて、
AndroidのGoogle ドライブでファイル(sample.txt)をダウンロードしたはずなのに、内蔵ストレージにはないみたい。
というか、ファイルがどこにあるかわからない。
それで、実機でファイルを読み書きできない。
ただし、Android Studioで、/storage/sdcard/Download/sample.txtは、読み書きできます。
実機だと上手くいかない。なぜ。(Nexus 5x)
以下のソースコードで問題がありましたら、ご教授ください。
static String path;
path = Environment.getExternalStorageDirectory().getPath() + "/Download/sample.txt";
try {
FileInputStream fis = new FileInputStream(path);
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
br.close();
}
catch(IOException e) {
flg = 1;
}
if(flg == 1) {
try {
FileOutputStream fos = new FileOutputStream(path);
OutputStreamWriter osw = new OutputStreamWriter(fos);
BufferedWriter bw = new BufferedWriter(osw);
bw.write("+1, 給 料 ,0,\n");
bw.write("+2, 賞 与 ,0,\n");
bw.write("-1, 食 費 ,0,\n");
bw.write("-2, 家 賃 ,0,\n");
bw.write("-3, 光熱費 ,0,\n");
bw.write("-4, 通信費 ,0,\n");
bw.write("-5, 小遣い ,0,\n");
bw.write("-6, 雑 費 ,0,\n");
bw.flush();
bw.close();
}
catch(IOException e) {
System.exit(1);
}
}
補足
クラウドのGoogle ドライブのファイル(sample.txt)への反映方法は、以下です。
①AndroidのGoogle ドライブのマイドライブで「ダウンロード」を選択、内蔵ストレージに保存、
②自作アプリで、内蔵ストレージから、ファイルを読み込み、データを更新、内蔵ストレージに書き込み、
③AndroidのGoogle ドライブで「アップロード」を選択、クラウドのGoogle ドライブのファイル(sample.txt)に反映
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。