Files类的使用演示
package com.nio;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.commons.io.FileUtils;
// Files类的使用演示
public class FilesTest {
public static void main(String[] args) throws IOException{
Files.copy(Paths.get("access.txt"),
new FileOutputStream("access_c.txt"));
// Path和File类的转换
File file = new File("access.txt");
Path path = file.toPath();
System.out.println(path.getFileName());
System.out.println(path.getName(0));
System.out.println(path.endsWith(Paths.get("access1.txt")));
File file2 = path.toFile();
System.out.println(file2.getName());
}
}