编程知识 cdmana.com

Java: files class reads and writes files

name.txt

 Liu bei 
 Zhang Fei 
 Guan yu 

Files Read the file

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

/**
 * Files @since 1.7
 */
public class FileDemo {
    
    public static void main(String[] args) throws IOException {
    
        //  Read the file 
        List<String> lines = Files.readAllLines(Paths.get("name.txt"));
        System.out.println(lines);
        // [ Liu bei ,  Zhang Fei ,  Guan yu ]

        //  write file 
        Files.write(Paths.get("name-1.txt"), lines);
    }
}

版权声明
本文为[Peng Shiyu]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224171911711f.html

Scroll to Top