Example usage for java.io File getParent

List of usage examples for java.io File getParent

Introduction

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

Prototype

public String getParent() 

Source Link

Document

Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.

Usage

From source file:fr.cls.atoll.motu.library.misc.vfs.VFSManager.java

/**
 * Creates the local file.// w w  w  .  j a v a 2  s .  co m
 * 
 * @param localFile the local file
 * 
 * @return the file
 * 
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static File createLocalFile(String localFile) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("createLocalFile(String) - entering");
    }

    File newFile = new File(localFile);
    File path = new File(newFile.getParent());
    path.mkdirs();
    newFile.createNewFile();

    if (LOG.isDebugEnabled()) {
        LOG.debug("createLocalFile(String) - exiting");
    }
    return newFile;

}

From source file:com.itemanalysis.jmetrik.data.JmetrikFileImporterTest.java

@Test
public void exam1ImportTest() {
    System.out.println("JmetrikFileImporterTest: Importing ./data/exam1-raw-data.csv");

    ClassLoader classLoader = getClass().getClassLoader();
    File f = new File(classLoader.getResource("data/exam1-raw-data.csv").getFile());
    String path = f.getParent();
    File outputFile = new File(path + File.separator + "exam1.jmetrik");
    try {/*from w ww .j av  a  2s .c o m*/
        outputFile.createNewFile();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

    ImportDataCommand command = new ImportDataCommand();
    command.setDataFileOption(f.getAbsolutePath());
    command.setOutfileOption(outputFile.getAbsolutePath());
    command.setDelimiter("comma");
    String[] selectAllOptions = { "header", "overwrite" };
    command.setOptionsOption(selectAllOptions);

    JmetrikFileImporter fileImporter = new JmetrikFileImporter(command);
    fileImporter.doInBackground();
}

From source file:com.photon.phresco.framework.param.impl.IosDeployValidationImpl.java

private StringBuilder getBuildInfoPath(String rootModulePath, String subModuleName) throws PhrescoException {
    File pomFileLocation = Utility.getPomFileLocation(rootModulePath, subModuleName);
    StringBuilder builder = new StringBuilder(pomFileLocation.getParent());
    builder.append(File.separator);
    builder.append(DO_NOT_CHECKIN_DIR);//from w w w .j ava2s.  co m
    builder.append(File.separator);
    builder.append(BUILD);
    builder.append(File.separator);
    builder.append(BUILD_INFO_FILE_NAME);
    return builder;
}

From source file:cc.creativecomputing.io.CCIOUtil.java

/**
 * Checks if the given path is absolute and at least contains existing folders.
 * @param thePath/*w ww .  j ava  2 s .c o m*/
 * @return true if the path is absolute and contains folders that exist
 */
static boolean isPathExisting(final String thePath) {
    File myFile = new File(thePath);
    while (!myFile.exists()) {
        String myParent = myFile.getParent();
        if (myParent == null || myParent.equals("/"))
            return false;
        myFile = new File(myParent);
    }
    return true;
}

From source file:com.papteco.client.netty.SelProjectClientHandler.java

private void submitFileJobsToQueue(ProjectBean project) {
    for (FolderBean folder : project.getFolderTree()) {
        if (StringUtils.isNotEmpty(folder.getFolderName()) && folder.getFileTree() != null) {
            String folderName = folder.getFolderName();
            for (FileBean file : folder.getFileTree()) {
                File f = new File(folderName, file.getFileName());
                QueueItem q = new QueueItem("DOWNLOAD", prjCde, new String[] { f.getParent(), f.getName() },
                        "PENDING");
                QueueBuilder.submitSingleQueue(q);
            }//from  w w  w . j  av  a 2 s . com
        } else {
            logger.info("No Files in folder [" + folder.getFolderName() + "]");
        }

    }
}

From source file:com.meltmedia.cadmium.core.config.impl.PropertiesWriterImpl.java

@Override
public void persistProperties(Properties properties, File propsFile, String message, Logger log) {

    if (propsFile.canWrite() || !propsFile.exists()) {

        FileOutputStream out = null;

        try {/*from   w  w  w . j  a v  a 2  s  . co m*/

            ensureDirExists(propsFile.getParent());
            out = new FileOutputStream(propsFile);
            properties.store(out, message);
            out.flush();
        } catch (Exception e) {

            log.warn("Failed to persist vault properties file.", e);
        } finally {
            IOUtils.closeQuietly(out);
        }

    }

}

From source file:FileViewer.java

/**
 * The real constructor. Create a FileViewer object to display the specified
 * file from the specified directory//from  ww  w  .jav a 2s . c o m
 */
public FileViewer(String directory, String filename) {
    super(); // Create the frame

    // Destroy the window when the user requests it
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            dispose();
        }
    });

    // Create a TextArea to display the contents of the file in
    textarea = new TextArea("", 24, 80);
    textarea.setFont(new Font("MonoSpaced", Font.PLAIN, 12));
    textarea.setEditable(false);
    this.add("Center", textarea);

    // Create a bottom panel to hold a couple of buttons in
    Panel p = new Panel();
    p.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 5));
    this.add(p, "South");

    // Create the buttons and arrange to handle button clicks
    Font font = new Font("SansSerif", Font.BOLD, 14);
    Button openfile = new Button("Open File");
    Button close = new Button("Close");
    openfile.addActionListener(this);
    openfile.setActionCommand("open");
    openfile.setFont(font);
    close.addActionListener(this);
    close.setActionCommand("close");
    close.setFont(font);
    p.add(openfile);
    p.add(close);

    this.pack();

    // Figure out the directory, from filename or current dir, if necessary
    if (directory == null) {
        File f;
        if ((filename != null) && (f = new File(filename)).isAbsolute()) {
            directory = f.getParent();
            filename = f.getName();
        } else
            directory = System.getProperty("user.dir");
    }

    this.directory = directory; // Remember the directory, for FileDialog
    setFile(directory, filename); // Now load and display the file
}

From source file:com.epam.wilma.webapp.config.servlet.stub.upload.helper.FileWriter.java

/**
 * Writes the content of an inputstream to a file.
 * @param inputStream the {@link InputStream} that will be written to the file
 * @param fileName the name of the file the <tt>inputStream</tt> will be written
 * @param exceptionMessage the message that a {@link CannotUploadExternalResourceException} should be thrown with
 *//*from  w  w w . j  a v a 2  s. c om*/
public void write(final InputStream inputStream, final String fileName, final String exceptionMessage) {
    String filePath = fileName;
    InputStream inputStreamToWrite = inputStream;
    if (fileName.endsWith(".class")) {
        InputStreamCopier inputStreamCopier = new InputStreamCopier(inputStream, fileName, exceptionMessage);
        InputStream byteArrayInputStream = inputStreamCopier.createCopy();
        filePath = classFilePathAssembler.createFilePath(byteArrayInputStream, fileName, exceptionMessage);
        inputStreamToWrite = inputStreamCopier.createCopy();
    } else if (fileName.endsWith(".jar")) {
        InputStreamCopier inputStreamCopier = new InputStreamCopier(inputStream, fileName, exceptionMessage);
        InputStream byteArrayInputStream = inputStreamCopier.createCopy();
        jarValidator.validateInputStream(byteArrayInputStream);
        inputStreamToWrite = inputStreamCopier.createCopy();
    }

    File newClass = fileFactory.createFile(filePath);
    //if file is in a package, create folder structure
    String directories = newClass.getParent();
    if (directories != null && !directories.isEmpty()) {
        (fileFactory.createFile(directories)).mkdirs();
    }
    try {
        // if file doesnt exists, then create it
        if (!newClass.exists()) {
            newClass.createNewFile();
        }
        FileOutputStream fos = fileOutputStreamFactory.createFileOutputStream(newClass);
        IOUtils.copy(inputStreamToWrite, fos);
        fos.close();
    } catch (IOException e) {
        throw new CannotUploadExternalResourceException(exceptionMessage + filePath, e);
    }
}

From source file:com.nidhinova.tools.ssh.SFTPClient.java

public void deepCreateRemoteFolder(String root, String relativepath) throws SftpException {
    this.sftp.cd(this.sftp.getHome());
    this.sftp.cd(root);
    List<File> folders = new ArrayList<File>();
    folders.add(new File(relativepath));
    try {// w  ww. j  ava  2s . c om
        File path = new File(relativepath);
        while (path != null) {
            path = new File(path.getParent());
            if (path != null) {
                folders.add(path);
            }
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String path = null;
    for (int i = folders.size() - 1; i > -1; i--) {
        path = folders.get(i).getPath().replace('\\', '/');
        this.sftp.mkdir(path);
        _logger.debug("Created folder >>" + path);
    }

}

From source file:download.XBRLFileCleaner.java

/**
 * Deletes all non xbrl file in the, master directory
 *
 * @throws java.io.IOException/*from w ww.j  a  va2  s  .c om*/
 */
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"));
        }
    }

}