環境変数を使用して外部ストレージにデータを書き込んでいます。正常に動作します。内部ストレージへの書き込みを試みたいのですが。次のコードを使用するとエラーが発生します。
public class B{
public void write(long l){
File root = new File(getFilesDir(), "Traces");
File gpxfile = new File(root, "Collection.txt");
if(gpxfile.exists()){
FileWriter writer = new FileWriter(gpxfile,true);
writer.append(Long.toString(l));
writer.flush();
writer.close();
}
私が得ているエラーは、'メソッドgetFilesDir()が未定義です'メソッドgetFilesDir()を作成します。コンテキストを割り当ててみました。何かのようなもの
context.getFilesDir()
と定義
Context context = MainActivity();% in main activity from where I am calling this writefunction.