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

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);        
    }
    
}

你可能感兴趣的:(java - File.separator和路径中的斜杠之间的区别)