NIO Demo

private static List getLines(File file) {
        try {
            return Files.readAllLines(file.toPath());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

private static writeFile(List strings){
    File wFile = new File("xxx");
        if(!file.exists()){
            wFile.createNewFile();
        }else{
            wFile.delete();
            wFile.createNewFile();
        }
    Files.write(wFile.toPath(), strings);
}

你可能感兴趣的:(#,java)