private static void writeUsingFiles(String data) {
try {
Files.write(Paths.get("/Users/pankaj/files.txt"), data.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
最少行數的讀檔:
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public static void main(String[] args) throws IOException {
String content = new String(Files.readAllBytes(Paths.get("duke.java")));
}
參考:
讀檔:
http://www.adam-bien.com/roller/abien/entry/java_8_reading_a_file
寫檔:
https://www.journaldev.com/878/java-write-to-file
沒有留言:
張貼留言