有点晚了,简单记录一下草稿
package com.tools;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
public class FileUtils {
public void writeFile(){
}
public void readFile(){
try {
String s = Files.readString(Path.of("src/com/resource/fruit.json"), StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void json(){
}
public void delete(){
try {
Files.delete(Path.of("src/com/resource/fruit1.json"));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void writeProperties() {
Properties p = new Properties();
try {
InputStream fi = new FileInputStream("src/com/resource/fruit.properties");
p.load(fi);
p.put("a","bbbb");
System.out.println(p);
} catch (IOException e) {
throw new RuntimeException(e);
}
System.out.println("====");
try (BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream("src/com/resource/fruit.properties"))) {
p.store(bos, null);
}catch (Exception e){
System.out.println(e);
}
}
public static void main(String[] args) {
FileUtils fileUtils = new FileUtils();
fileUtils.delete();
}
}