Here you can find the source of toFile(String path)
Parameter | Description |
---|---|
path | e.g. C:\foo\bar.txt |
public static File toFile(String path)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { /**//from ww w. j ava 2s . c o m * Like new File(path) EXCEPT this will convert Windows/Max/Linux separators into the local format. * Use-case: so getParentFile() will work reliably. * @param path e.g. C:\foo\bar.txt * @return e.g. C:/foo/bar.txt * Note: this does not remove or change windows drive markers */ public static File toFile(String path) { if (path == null) return null; if (File.separatorChar == '\\') { // From Windows to Linux/Mac return new File(path.replace('/', File.separatorChar)); } else { // From Linux/Mac to Windows return new File(path.replace('\\', File.separatorChar)); } } }