因為太常用但是又懶得每次重寫…暫時放一下
之前貼上來不知道為什麼少了幾個字跟 getByte…修正一下 (汗)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
public static boolean StringToFile(String file_path, String rawData) { boolean result = false; try { String charset = "UTF-8"; int buffer_size = 8192; FileOutputStream out = new FileOutputStream(file_path); OutputStreamWriter osw = new OutputStreamWriter(out, charset); BufferedWriter bw = new BufferedWriter(osw, buffer_size); out.write(rawData.getBytes()); // 寫完記得關掉 out.close(); bw.close(); result = true; } catch (Exception e) { Log.w(tag, "write string to file failed, " + e.getMessage()); } return result; } |