import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class FileUtil {
public static String read(String path) {
File file = new File(path);
if (!file.exists()) {
file.getParentFile().mkdirs();
return "";
}
StringBuilder sb = new StringBuilder();
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
public static void save(String json, String path) {
File file = new File(path);
if (!file.exists()) {
file.getParentFile().mkdirs();
}
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(json);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
android 保存和读取String到sdcard
最新推荐文章于 2021-05-25 14:43:52 发布