集册 Java实例教程 路径创建移动/删除文件

路径创建移动/删除文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

387
路径创建移动/删除文件
/** from 时代Java - nowjava.com**/



import java.io.IOException;

import java.nio.file.FileSystems;

import java.nio.file.Files;

import java.nio.file.Path;

import java.nio.file.StandardCopyOption;

import java.util.Properties;

import java.util.logging.Level;

import java.util.logging.Logger;


public class Main {


    public static void main(String[] args) {


        try {
        /**
        N  o w  J a v a . c o m 提供 
        **/

            Properties props = System.getProperties();

            String homePath = props.get("user.home").toString();

            Path sampleFile = FileSystems.getDefault().getPath(homePath + "/test1.txt");

            Files.deleteIfExists(sampleFile);

            Files.createFile(sampleFile); // create an empty file

            Files.copy(sampleFile, FileSystems.getDefault().getPath(homePath + "/test2.txt"), StandardCopyOption.COPY_ATTRIBUTES.REPLACE_EXISTING);

            // Creating a link

            Path dir = FileSystems.getDefault().getPath(homePath + "/a/symlink");

            Files.dele
展开阅读全文