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:de.dakror.virtualhub.server.DBManager.java

public static Tags tags(File f, String catalog, Tags t) {
    try {/*from   ww  w  .  j a v a2 s. c o  m*/
        if (t == null) {
            ResultSet rs = connection.createStatement().executeQuery("SELECT TAGS FROM TAGS WHERE PATH = \""
                    + f.getPath().replace("\\", "/") + "\" AND CATALOG = \"" + catalog + "\"");
            if (!rs.next())
                return new Tags();

            return new Tags(rs.getString(1).split(", "));
        } else {
            if (t.getTags().length == 0)
                connection.createStatement().executeUpdate("DELETE FROM TAGS WHERE PATH = \""
                        + f.getPath().replace("\\", "/") + "\" AND CATALOG = \"" + catalog + "\"");
            else
                connection.createStatement()
                        .executeUpdate("INSERT OR REPLACE INTO TAGS VALUES(\"" + f.getPath().replace("\\", "/")
                                + "\", \"" + catalog + "\", \"" + t.serialize() + "\")");
        }
    } catch (SQLException e1) {
        e1.printStackTrace();
    }
    return null;
}

From source file:brut.util.OS.java

public static void cpdir(File src, File dest) throws BrutException {
    dest.mkdirs();/*from  w  ww.  j  av a  2 s . com*/
    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 BrutException("Could not copy file: " + file, ex);
        }
    }
}

From source file:com.redhat.rhn.testing.RhnBaseTestCase.java

protected static void createDirIfNotExists(File dir) {
    String error = "Could not create the following directory:[" + dir.getPath()
            + "] . Please create that directory before proceeding with the tests";
    if (dir.exists() && !dir.isDirectory()) {
        if (!dir.renameTo(new File(dir.getPath() + ".bak")) && !dir.delete()) {
            throw new RuntimeException(error);
        }/*from   w  w w .j  a va 2  s  .c  om*/
    }

    if (!dir.exists() && !dir.mkdirs()) {
        throw new RuntimeException(error);
    }
}

From source file:com.microsoft.alm.plugin.idea.common.utils.IdeaHelper.java

/**
 * Check if a file is executable and if not sets it to be executable. When the plugin is unzipped,
 * the permissions of a file is not persisted so that is why a check is needed.
 *
 * @param executable executable file for application
 * @throws FileNotFoundException//  ww  w.  java 2  s.com
 */
public static void setExecutablePermissions(final File executable) throws FileNotFoundException {
    if (!executable.exists()) {
        throw new FileNotFoundException(executable.getPath() + " not found while trying to set permissions.");
    }

    // set the executable to execute for all users
    if (!executable.canExecute()) {
        executable.setExecutable(true, false);
    }
}

From source file:com.fjn.helper.common.io.file.common.FileUtil.java

/**
 * ?parentDir?childDir/* w  ww . j  av  a2  s. c o  m*/
 * @param parentDir
 * @param childDir
 * @return
 */
public static File ensureChildDirExists(File parentDir, String childDir) {
    parentDir = ensureDirExists(parentDir);
    String child = parentDir.getPath() + File.separator + childDir;
    File file = ensureDirExists(child);
    return file;
}

From source file:ezbake.frack.submitter.util.JarUtil.java

private static void add(File source, final String prefix, JarOutputStream target) throws IOException {
    BufferedInputStream in = null;
    log.debug("Adding file {} to jar", source.getName());
    try {/*w w  w  .ja v  a2  s.c o m*/
        String entryPath = source.getPath().replace("\\", "/").replace(prefix, "");
        if (entryPath.startsWith("/")) {
            entryPath = entryPath.substring(1);
        }
        if (source.isDirectory()) {
            if (!entryPath.isEmpty()) {
                if (!entryPath.endsWith("/")) {
                    entryPath += "/";
                }
                JarEntry entry = new JarEntry(entryPath);
                entry.setTime(source.lastModified());
                target.putNextEntry(entry);
                target.closeEntry();
            }
            for (File nestedFile : source.listFiles()) {
                add(nestedFile, prefix, target);
            }
        } else {
            JarEntry entry = new JarEntry(entryPath);
            entry.setTime(source.lastModified());
            target.putNextEntry(entry);
            in = new BufferedInputStream(new FileInputStream(source));

            byte[] buffer = new byte[BUFFER_SIZE];
            int len;
            while ((len = in.read(buffer)) > 0) {
                target.write(buffer, 0, len);
            }
            target.closeEntry();
        }
    } finally {
        if (in != null) {
            in.close();
        }
    }
}

From source file:com.cherong.mock.common.base.util.EncryptionUtil.java

/**
 *   ??0-F?4838??/* ww w . j av  a 2  s .c  o m*/
 * AD67EA2F3BE6E5ADD368DFE03120B5DF92A8FD8FEC2F0746  AD67EA2F3BE6E5AD
 * DES? D368DFE03120B5DF DES? 92A8FD8FEC2F0746 DES? 
 * ??
 * 
 * @param fileIn
 * @param key
 */
public static String decrypt(File fileIn, String key) {
    try {
        if (key.length() == 48) {
            String path = fileIn.getPath();
            // path = path.substring(0, path.length() - 5);

            byte[] bytK1 = string2Byte(key.substring(0, 16));
            byte[] bytK2 = string2Byte(key.substring(16, 32));
            byte[] bytK3 = string2Byte(key.substring(32, 48));

            FileInputStream fis = new FileInputStream(path);
            byte[] bytIn = new byte[(int) fileIn.length()];
            for (int i = 0; i < fileIn.length(); i++) {
                bytIn[i] = (byte) fis.read();
            }

            // 
            byte[] bytOut = decryptByDES(decryptByDES(decryptByDES(bytIn, bytK3), bytK2), bytK1);

            fis.close();

            return new String(bytOut);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Compress.java

/** Zip the contents of the directory, and save it in the zipfile */
public static void zipDirectory(String dir, String zipfile) throws IOException, IllegalArgumentException {
    // Check that the directory is a directory, and get its contents
    File d = new File(dir);
    if (!d.isDirectory())
        throw new IllegalArgumentException("Compress: not a directory:  " + dir);
    String[] entries = d.list();//from w w  w  . j  a va  2  s .c  o  m
    byte[] buffer = new byte[4096]; // Create a buffer for copying
    int bytes_read;

    // Create a stream to compress data and write it to the zipfile
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile));

    // Loop through all entries in the directory
    for (int i = 0; i < entries.length; i++) {
        File f = new File(d, entries[i]);
        if (f.isDirectory())
            continue; // Don't zip sub-directories
        FileInputStream in = new FileInputStream(f); // Stream to read file
        ZipEntry entry = new ZipEntry(f.getPath()); // Make a ZipEntry
        out.putNextEntry(entry); // Store entry
        while ((bytes_read = in.read(buffer)) != -1)
            // Copy bytes
            out.write(buffer, 0, bytes_read);
        in.close(); // Close input stream
    }
    // When we're done with the whole loop, close the output stream
    out.close();
}

From source file:com.snipme.download.ImageDownloader.java

public static File getImage(String imagename) {

    File mediaImage = null;//from ww  w  .  j av a  2s  . c om
    try {
        String root = Environment.getExternalStorageDirectory().toString();
        File myDir = new File(root);
        if (!myDir.exists())
            return null;

        mediaImage = new File(myDir.getPath() + "/.your_specific_directory/" + imagename);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return mediaImage;
}

From source file:com.silverpeas.util.ZipManager.java

/**
 * Mthode compressant un dossier de faon rcursive au format zip.
 *
 * @param folderToZip - dossier  compresser
 * @param zipFile - fichier zip  creer//from   w w w  .j  av a  2 s  . c o  m
 * @return la taille du fichier zip gnr en octets
 * @throws FileNotFoundException
 * @throws IOException
 */
public static long compressPathToZip(File folderToZip, File zipFile) throws IOException {
    ZipArchiveOutputStream zos = null;
    try {
        // cration du flux zip
        zos = new ZipArchiveOutputStream(new FileOutputStream(zipFile));
        zos.setFallbackToUTF8(true);
        zos.setCreateUnicodeExtraFields(NOT_ENCODEABLE);
        zos.setEncoding(CharEncoding.UTF_8);
        Collection<File> folderContent = FileUtils.listFiles(folderToZip, null, true);
        for (File file : folderContent) {
            String entryName = file.getPath().substring(folderToZip.getParent().length() + 1);
            entryName = FilenameUtils.separatorsToUnix(entryName);
            zos.putArchiveEntry(new ZipArchiveEntry(entryName));
            InputStream in = new FileInputStream(file);
            IOUtils.copy(in, zos);
            zos.closeArchiveEntry();
            IOUtils.closeQuietly(in);
        }
    } finally {
        if (zos != null) {
            IOUtils.closeQuietly(zos);
        }
    }
    return zipFile.length();
}