Java File Object Create toFile(String path)

Here you can find the source of toFile(String path)

Description

create a file from path

License

LGPL

Parameter

Parameter Description
path a parameter

Return

new File Object

Declaration

public static File toFile(String path) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.File;

public class Main {
    /**/*from   w w w  .  j  av a 2s .  com*/
     * Field <code>FILE_SEPERATOR</code>
     */
    public static final char FILE_SEPERATOR = File.separatorChar;
    /**
     * Field <code>FILE_ANTI_SEPERATOR</code>
     */
    public static final char FILE_ANTI_SEPERATOR = (FILE_SEPERATOR == '/') ? '\\' : '/';

    /** 
     * create a file from path
     * @param path
     * @return new File Object
     */
    public static File toFile(String path) {
        return new File(path.replace(FILE_ANTI_SEPERATOR, FILE_SEPERATOR));
    }

    /**
     * create a File from parent file and string
     * @param parent 
     * @param path 
     * @return new File Object
     */
    public static File toFile(File parent, String path) {
        return new File(parent, path.replace(FILE_ANTI_SEPERATOR, FILE_SEPERATOR));
    }

    /**
     * create a File from parent file and string
     * @param parent 
     * @param path 
     * @return new File Object
     */
    public static File toFile(String parent, String path) {
        return new File(parent.replace(FILE_ANTI_SEPERATOR, FILE_SEPERATOR),
                path.replace(FILE_ANTI_SEPERATOR, FILE_SEPERATOR));
    }
}

Related

  1. toFile(String fileName, String txt)
  2. toFile(String inFile)
  3. toFile(String line)
  4. toFile(String path)
  5. toFile(String path)
  6. toFile(String path)
  7. toFile(String path)
  8. toFile(String path, String toWrite)
  9. toFile(String s)