Example usage for java.io File separatorChar

List of usage examples for java.io File separatorChar

Introduction

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

Prototype

char separatorChar

To view the source code for java.io File separatorChar.

Click Source Link

Document

The system-dependent default name-separator character.

Usage

From source file:com.genentech.retrival.SDFExport.SDFSDFExporter.java

public static SDFSDFExporter createFromFile(String sqlFile, String rowStmtName, String inFile, String outFile,
        String[] tagNames, boolean printIfNoRecord, String newLineReplacement) throws IOException {
    if (sqlFile == null)
        sqlFile = "sql.xml";

    File sqlFILE = new File(sqlFile);
    if (!sqlFILE.exists()) {
        sqlFILE = new File(
                Settings.AESTEL_INSTALL_PATH + File.separatorChar + "config" + File.separatorChar + "sdfExport",
                sqlFile);/*w ww  . ja  v a  2  s  .  c om*/
        if (!sqlFILE.exists())
            sqlFILE = new File(Settings.AESTEL_INSTALL_PATH + File.separatorChar + "config" + File.separatorChar
                    + "sdfExport", sqlFile + ".xml");

        if (!sqlFILE.exists())
            throw new IOException(sqlFile + " not found!");
    }
    SQLStatement stmt = SQLStatement.createFromFile(sqlFILE, rowStmtName);

    return new SDFSDFExporter(stmt, inFile, outFile, tagNames, printIfNoRecord, newLineReplacement);
}

From source file:com.mugarov.alfapipe.model.programparse.generators.GeneratorCore.java

public GeneratorCore(String path, ArrayList<ParseableProgram> defaultList) {
    this.available = new ArrayList<>();
    this.path = ParameterPool.CONFIG_PREFIX + System.getProperty("user.name") + File.separatorChar
            + ParameterPool.CONFIG_INFIX + File.separatorChar + path;

    this.localFile = new File(this.path);
    if (!this.localFile.getParentFile().exists()) {
        this.localFile.getParentFile().mkdirs();
    }//from  w  ww  .j  a  v  a 2  s  .  c  om
    if (!localFile.exists()) {
        System.out.println("File does not exist! Creating default List in " + this.path);
        this.available = defaultList;
        this.parseOut();
    } else {
        this.parseIn();
    }

}

From source file:Main.java

/**
 * Builds a specific file path given a path format and the info needed for replacing placeholders.
 *
 * @param filePathFormat The format string defining how to build the file path.
 * @param locale The locale for the file path, or null if not applicable.
 * @param inputFilePath Only applicable if you need to replace the placeholders {INPUT_DIRECTORY},
 *     {INPUT_FILE_NAME}, and {INPUT_FILE_NAME_NO_EXT} (otherwise pass null). This is the full
 *     path of the input file (including the input path prefix).
 * @param inputPathPrefix The input path prefix, or empty string if none.
 * @return The output file path corresponding to the given input file path.
 *//*from  ww  w.  j a v  a  2s .  co m*/
public static String buildFilePath(String filePathFormat, @Nullable String locale,
        @Nullable String inputFilePath, String inputPathPrefix) {

    String path = filePathFormat;

    if (locale != null) {
        path = path.replace("{LOCALE}", locale);
        path = path.replace("{LOCALE_LOWER_CASE}", locale.toLowerCase().replace('-', '_'));
    }

    path = path.replace("{INPUT_PREFIX}", inputPathPrefix);

    if (inputFilePath != null) {
        // Remove the prefix (if any) from the input file path.
        inputFilePath = inputFilePath.substring(inputPathPrefix.length());

        // Compute directory and file name.
        int lastSlashIndex = inputFilePath.lastIndexOf(File.separatorChar);
        String directory = inputFilePath.substring(0, lastSlashIndex + 1);
        String fileName = inputFilePath.substring(lastSlashIndex + 1);

        // Compute file name without extension.
        int lastDotIndex = fileName.lastIndexOf('.');
        if (lastDotIndex == -1) {
            lastDotIndex = fileName.length();
        }
        String fileNameNoExt = fileName.substring(0, lastDotIndex);

        // Substitute placeholders.
        path = path.replace("{INPUT_DIRECTORY}", directory);
        path = path.replace("{INPUT_FILE_NAME}", fileName);
        path = path.replace("{INPUT_FILE_NAME_NO_EXT}", fileNameNoExt);
    }

    return path;
}

From source file:com.guye.baffle.util.OS.java

public static void cpdir(File src, File dest) throws BaffleException {
    dest.mkdirs();//w  w w. j  av a2s .  co m
    File[] files = src.listFiles();
    for (int i = 0; i < files.length; i++) {
        File file = files[i];
        File destFile = new File(dest.getPath() + File.separatorChar + file.getName());
        if (file.isDirectory()) {
            cpdir(file, destFile);
            continue;
        }
        try {
            InputStream in = new FileInputStream(file);
            OutputStream out = new FileOutputStream(destFile);
            IOUtils.copy(in, out);
            in.close();
            out.close();
        } catch (IOException ex) {
            throw new BaffleException("Could not copy file: " + file, ex);
        }
    }
}

From source file:de.pdark.dsmp.ProxyDownloadTest.java

@Test
public void testMkdirs() throws Exception {
    URL url = new URL("http://repo1.maven.org/maven2/org/apache/commons/commons-parent/1/commons-parent-1.pom");
    File f = RequestHandler.getCacheFile(url, cacheDir);
    String expected = cacheDir.getAbsolutePath().replace(File.separatorChar, '/')
            + "/repo1.maven.org/maven2/org/apache/commons/commons-parent/1/commons-parent-1.pom";
    String s = f.getAbsolutePath().replace(File.separatorChar, '/');
    assertEquals(expected, s);//from  w  w w.ja v  a2 s. co  m
}

From source file:com.kylinolap.job.tools.OptionsHelper.java

public static String convertToFileURL(String path) {
    if (File.separatorChar != '/') {
        path = path.replace(File.separatorChar, '/');
    }/*from   www  . j a v  a2 s . c om*/

    return path;
}

From source file:URLUtil.java

/**
 * Method that tries to figure out how to create valid URL from a system id,
 * without additional contextual information. If we could use URIs this might
 * be easier to do, but they are part of JDK 1.4, and preferably code should
 * only require 1.2 (or maybe 1.3)/*from  ww  w.j av a  2  s . c  o m*/
 */
public static URL urlFromSystemId(String sysId) throws IOException {
    try {
        /*
         * Ok, does it look like a full URL? For one, you need a colon. Also, to
         * reduce likelihood of collision with Windows paths, let's only accept it
         * if there are 3 preceding other chars... Not sure if Mac might be a
         * problem? (it uses ':' as file path separator, alas, at least prior to
         * MacOS X)
         */
        int ix = sysId.indexOf(':', 0);
        /*
         * Also, protocols are generally fairly short, usually 3 or 4 chars (http,
         * ftp, urn); so let's put upper limit of 8 chars too
         */
        if (ix >= 3 && ix <= 8) {
            return new URL(sysId);
        }
        // Ok, let's just assume it's local file reference...
        /*
         * 24-May-2006, TSa: Amazingly, this single call does show in profiling,
         * for small docs. The problem is that deep down it tries to check
         * physical file system, to check if the File pointed to is a directory:
         * and that is (relatively speaking) a very expensive call. Since in this
         * particular case it should never be a dir (and/or doesn't matter), let's
         * just implement conversion locally
         */
        String absPath = new java.io.File(sysId).getAbsolutePath();
        // Need to convert colons/backslashes to regular slashes?
        {
            char sep = File.separatorChar;
            if (sep != '/') {
                absPath = absPath.replace(sep, '/');
            }
        }
        if (absPath.length() > 0 && absPath.charAt(0) != '/') {
            absPath = "/" + absPath;
        }
        return new URL("file", "", absPath);
    } catch (MalformedURLException e) {

        return null; // never gets here
    }
}

From source file:download.XBRLFileCleaner.java

/**
 * Deletes all non xbrl file in the, master directory
 *
 * @throws java.io.IOException//from www .ja va  2s  .com
 */
public void deleteNonXBRLFiles() throws IOException {
    File masterDirectory = new File(XBRLFilePaths.XBRL_FILING_DIRECTORY);

    // lists all files that are not directories except rfd object files
    Collection<File> files = FileUtils.listFiles(masterDirectory, new String[] { "zip", "xdr", "xsd", "xml" },
            true);

    // deletes the files that are not xbrl files
    for (File file : files) {
        if (!isXBRLFile(file.getName())) {
            Files.delete(Paths.get(file.getAbsolutePath()));
        } else {
            file.renameTo(
                    new File(file.getParent() + File.separatorChar + file.getParentFile().getName() + ".xml"));
        }
    }

}

From source file:Main.java

public static void unzipEPub(String inputZip, String destinationDirectory) throws IOException {
    int BUFFER = 2048;
    List zipFiles = new ArrayList();
    File sourceZipFile = new File(inputZip);
    File unzipDestinationDirectory = new File(destinationDirectory);
    unzipDestinationDirectory.mkdir();// w w w  .j a  v a 2 s . c  o  m

    ZipFile zipFile;
    zipFile = new ZipFile(sourceZipFile, ZipFile.OPEN_READ);
    Enumeration zipFileEntries = zipFile.entries();

    // Process each entry
    while (zipFileEntries.hasMoreElements()) {

        ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
        String currentEntry = entry.getName();
        File destFile = new File(unzipDestinationDirectory, currentEntry);

        if (currentEntry.endsWith(".zip")) {
            zipFiles.add(destFile.getAbsolutePath());
        }

        File destinationParent = destFile.getParentFile();
        destinationParent.mkdirs();

        if (!entry.isDirectory()) {
            BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(entry));
            int currentByte;
            // buffer for writing file
            byte data[] = new byte[BUFFER];

            FileOutputStream fos = new FileOutputStream(destFile);
            BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);

            while ((currentByte = is.read(data, 0, BUFFER)) != -1) {
                dest.write(data, 0, currentByte);
            }
            dest.flush();
            dest.close();
            is.close();

        }

    }
    zipFile.close();

    for (Iterator iter = zipFiles.iterator(); iter.hasNext();) {
        String zipName = (String) iter.next();
        unzipEPub(zipName,
                destinationDirectory + File.separatorChar + zipName.substring(0, zipName.lastIndexOf(".zip")));
    }
}

From source file:net.sasasin.sreader.batch.publish.HtmlPublisher.java

@Override
public void finalize() {
    s.append("</body><html>");
    try {/*from  w ww . j a v a2 s. c o m*/
        FileUtils.writeStringToFile(
                new File(System.getProperty("user.home") + File.separatorChar + "sreader.html"), s.toString());
    } catch (IOException e) {
        e.printStackTrace();
    }
}