java - File.separator和路径中的斜杠之间的区

2019-07-09  本文已影响0人  商山夜行人
package com.demo;

import java.io.File;
import java.io.IOException;

public class TestFileSeparator {

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        String path = new File(".").getCanonicalPath();
        String fileName = "TestFileSeparator.java";
        File file = null;
        file = new File(path + File.separator + fileName);
        System.out.println("[File.separator]" + file.exists() + "   " + file);  
        file = new File(path + "\\" + fileName);
        System.out.println("\\" + file.exists() + "   " + file);        
    }
    
}
上一篇下一篇

猜你喜欢

热点阅读