2022年7月30日

Android 寫入檔案API

 



import android.util.Log;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;

public class File_write_tool {

public static String TAG="File_write_tool";

public void write(File file, ArrayList<String> list){


try {
FileOutputStream stream = new FileOutputStream(file);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stream));

for(int i=0;i<list.size();i++){
String str=list.get(i);
writer.write(str);
writer.newLine();
}

writer.close();

}catch (Exception e){

Log.e(TAG,e.getMessage());

}


}



}

沒有留言:

張貼留言