Example usage for java.io File getPath

List of usage examples for java.io File getPath

Introduction

In this page you can find the example usage for java.io File getPath.

Prototype

public String getPath() 

Source Link

Document

Converts this abstract pathname into a pathname string.

Usage

From source file:net.firejack.platform.core.utils.FileUtils.java

/**
 * @param parent/*from   www . j  a v a2s .  c o  m*/
 * @param children
 *
 * @return
 */
public static File create(File parent, String... children) {
    return create(parent.getPath(), children);
}

From source file:Main.java

public static File WriteStreamToFile(InputStream resStream) {
    try {// ww w  . j  a  va2s  .  c  o  m
        byte[] bytes = new byte[resStream.available()];
        File tmpFile = File.createTempFile("z4-", ".tmp");
        tmpFile.deleteOnExit();
        DataInputStream dis = new DataInputStream(resStream);
        dis.readFully(bytes);
        FileOutputStream foutStream = new FileOutputStream(tmpFile.getPath());
        foutStream.write(bytes);
        foutStream.close();
        dis.close();
        return tmpFile;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

/**
 * Check if a filename is "safe" (no metacharacters or spaces).
 * //w w  w .  ja  v a2s  .c om
 * @param file
 *            The file to check
 */
public static boolean isFilenameSafe(File file) {
    // Note, we check whether it matches what's known to be safe,
    // rather than what's known to be unsafe. Non-ASCII, control
    // characters, etc. are all unsafe by default.
    return SAFE_FILENAME_PATTERN.matcher(file.getPath()).matches();
}

From source file:Main.java

/** Copy files or folders */
public static boolean copyFiles(File srcFile, File dstFile) {
    boolean ret = true;

    if (srcFile.getParent().equals(dstFile)) {
        return false;
    }/*ww  w. ja  v  a 2s . co  m*/

    if (srcFile.isDirectory()) {
        if (dstFile.getPath().indexOf(srcFile.getPath()) == 0) {
            return false;
        } else {
            if (copyDir(srcFile, dstFile) == false) {
                return false;
            }
        }
    } else {
        ret = copyFile(srcFile, dstFile);
    }

    return ret;
}

From source file:io.pivotal.strepsirrhini.chaosloris.docs.MarkdownWriterResolver.java

private static File makeRelativeToConfiguredOutputDir(File outputFile, RestDocumentationContext context) {
    File configuredOutputDir = context.getOutputDirectory();
    if (configuredOutputDir != null) {
        return new File(configuredOutputDir, outputFile.getPath());
    }/* w w w  .  j  a  va2 s  . com*/
    return null;
}

From source file:com.cognifide.qa.bb.utils.PropertyUtils.java

private static void loadProperties(File file, Properties properties) throws IOException {
    if (!file.exists()) {
        LOG.warn("{} file doesn't exists.", file.getPath());
    } else {//w  w  w .ja  v  a2  s  .co m
        if (file.isDirectory()) {
            for (File child : file.listFiles()) {
                loadProperties(child, properties);
            }
        } else {
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));

            LOG.debug("loading properties from: {} (ie. {})", file, file.getAbsolutePath());
            try {
                properties.load(reader);
            } finally {
                reader.close();
            }
        }
    }
}

From source file:com.scaniatv.LangFileUpdater.java

/**
 * Method that gets a list of all lang files.
 * //from   w  ww  .  j av a  2s.c  o  m
 * @return 
 */
public static String[] getLangFiles() {
    Collection<File> files = FileUtils.listFiles(new File(DEFAULT_LANG_ROOT), TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);
    ArrayList<String> fileNames = new ArrayList<>();

    String sep = File.separator;

    files.forEach((File file) -> {
        fileNames.add(file.getPath().replace("." + sep + "scripts" + sep + "lang" + sep + "english" + sep, ""));
    });

    return fileNames.toArray(new String[fileNames.size()]);
}

From source file:edu.cuhk.hccl.cmd.AppSearchEngine.java

/**
 * Create index of RAMDirectory from a data folder with text files
 * @param dataFolder/*  w  w  w. j a  va 2s. c  o m*/
 * @param analyzer
 * @return
 * @throws IOException
 */
private static Directory createIndex(File dataFolder, StandardAnalyzer analyzer) throws IOException {

    Directory index = new RAMDirectory();
    IndexWriterConfig config = new IndexWriterConfig(Version.LATEST, analyzer);
    IndexWriter writer = new IndexWriter(index, config);

    Collection<File> files = FileUtils.listFiles(dataFolder, null, true);
    for (File file : files) {
        String path = file.getPath();
        String content = FileUtils.readFileToString(file);

        Document doc = new Document();

        doc.add(new StringField(PATH_FIELD, path, Field.Store.YES));
        doc.add(new Field(CONTENT_FIELD, content, TERM_STORED));

        writer.addDocument(doc);

        System.out.println("[INFO] Indexing file: " + path);
    }

    System.out.println("\n[INFO]" + files.size() + " files has been indexed.");

    writer.close();

    return index;
}

From source file:mesclasses.util.FileSaveUtil.java

public static File createNewSaveFile(File file) {
    try {/*  w w w.  ja  va 2  s. c om*/
        file.createNewFile();
        return file;
    } catch (IOException ex) {
        LOG.error("Le fichier " + file.getPath() + " ne peut pas tre cr");
        return null;
    }
}

From source file:Main.java

public static void deleteDirAllFile(String dirPath, int options) {
    File file = new File(dirPath);
    if (file.isDirectory()) {
        File[] fileList = file.listFiles();
        for (File f : fileList) {
            if (f.isDirectory() && (options != FILE_IGNORE_DIR)) {
                deleteDirAllFile(f.getPath(), options);
                f.delete();//from   ww  w  .j  a  v a 2s  . c o  m
            } else {
                f.delete();
            }
        }
    }
}