//字符串、json 写入文件
public static void writeStringToFile(String json, String filePath) {
File txt = new File(filePath);
if (!txt.exists()) {
try {
txt.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
byte[] bytes = json.getBytes(); //新加的
int b = json.length(); //改
FileOutputStream fos = null;
try {
fos = new FileOutputStream(txt);
fos.write(bytes);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
java、Android 字符串、json写入文件
最新推荐文章于 2024-08-09 03:55:40 发布