Example usage for java.io File getAbsoluteFile

List of usage examples for java.io File getAbsoluteFile

Introduction

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

Prototype

public File getAbsoluteFile() 

Source Link

Document

Returns the absolute form of this abstract pathname.

Usage

From source file:com.redhat.red.koji.build.Config.java

public void load(File configFile) throws IOException, ConfigurationException {
    if (configFile == null || !configFile.exists() || configFile.isDirectory()) {
        throw new ConfigurationException(
                "You must specify a valid file for reading configuration (file was: %s)", configFile);
    }/*  ww  w .j a  v a2  s  .c  om*/

    configDir = configFile.getAbsoluteFile().getParentFile();

    try (InputStream stream = new FileInputStream(configFile)) {
        new DotConfConfigurationReader(this).loadConfiguration(stream);
    }
}

From source file:jeplus.JEPlusProject.java

/**
 * Read the project from the given JSON file. 
 * @param file The File object associated with the file
 * @return a new project instance from the file
 * @throws java.io.IOException/*  www  .  j av a 2 s  .  co  m*/
 */
public static JEPlusProject loadFromJSON(File file) throws IOException {
    // Read JSON
    ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
    JEPlusProject project = mapper.readValue(file, JEPlusProject.class);
    // Set base dir
    String dir = file.getAbsoluteFile().getParent();
    dir = dir.concat(dir.endsWith(File.separator) ? "" : File.separator);
    // project.updateBaseDir(dir);
    project.setBaseDir(dir);
    // If parameter file is given, use the contents to override the parameters in the project
    if (project.ParamFile != null) {
        // Load parameters from text file, to replace the existing Parameters list and tree
        project.importParameterTableFile(new File(RelativeDirUtil.checkAbsolutePath(project.ParamFile, dir)));
    } else {
        // Reassign reference to project in all parameters, and build param tree
        if (project.getParameters() != null) {
            for (ParameterItem item : project.getParameters()) {
                item.setProject(project);
            }
            project.addParameterListAsBranch(null, project.getParameters());
        }
    }
    // If external RVX file is specified, use its contents for Rvx object
    if (project.RvxFile != null) {
        try {
            project.Rvx = RVX.getRVX(RelativeDirUtil.checkAbsolutePath(project.RvxFile, dir));
        } catch (IOException ioe) {
            logger.error("Cannot read the given RVX file", ioe);
        }
    }
    project.ContentChanged = false;
    // Return
    return project;
}

From source file:br.edu.ifpb.sislivros.model.ProcessadorFotos.java

public boolean salvarImagem(String path, FileItemStream item, String nameToSave) {
    try {/*from   www  .  ja v  a2s  . c  o  m*/
        File f = new File(path);
        //            File f = new File(path+File.separator+folder);            
        //            File parent = new File(f.getParent());
        //            
        //            if(!parent.exists())
        //                parent.mkdir();
        if (!f.exists()) {
            f.mkdir();
        }

        File savedFile = new File(f.getAbsoluteFile() + File.separator + nameToSave);
        FileOutputStream fos = new FileOutputStream(savedFile);

        InputStream is = item.openStream();

        int x = 0;
        byte[] b = new byte[1024];
        while ((x = is.read(b)) != -1) {
            fos.write(b, 0, x);
        }
        fos.flush();
        fos.close();

        return true;

    } catch (Exception ex) {
    }
    return false;
}

From source file:com.tvd.cocos2dx.popup.creator.file.FileUtils.java

public void replaceContent(String pFilePath) {
    try {//from w  w  w  .ja v a  2 s.co m
        String folderPath = pFilePath.substring(0, pFilePath.lastIndexOf('/'));
        File container = new File(folderPath);
        if (!container.exists()) {
            container.mkdirs();
        }
        File file = new File(pFilePath);

        //if file doesn't exists, then create it
        if (!file.exists()) {
            file.createNewFile();
        }

        FileWriter fileWriter = new FileWriter(file.getAbsoluteFile());
        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
        bufferedWriter.write(mContent);

        bufferedWriter.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.cyberway.issue.crawler.settings.XMLSettingsHandler.java

/** 
 * Initialize the SettingsHandler from a source.
 *
 * This method builds the settings data structure and initializes it with
 * settings from the order file given as a parameter. The intended use is
 * to create a new order file based on a default (template) order file.
 *
 * @param source the order file to initialize from.
 *//*from   w  w w  . j a va 2s . c om*/
public void initialize(File source) {
    File tmpOrderFile = orderFile;
    orderFile = source.getAbsoluteFile();
    this.initialize();
    orderFile = tmpOrderFile;
}

From source file:net.nicholaswilliams.java.licensing.encryption.TestFilePublicKeyDataProvider.java

@Test
public void testKeyFile02() throws IOException {
    final String fileName = "testKeyFile02.key";
    File file = new File(fileName);

    if (file.exists())
        FileUtils.forceDelete(file);//from   www.  java2  s.  c  o  m

    FilePublicKeyDataProvider provider = new FilePublicKeyDataProvider(file);

    assertNotNull("The key file should not be null.", provider.getPublicKeyFile());
    assertNotSame("The objects should not be the same.", file, provider.getPublicKeyFile());
    assertEquals("The key file is not correct.", file.getAbsoluteFile(), provider.getPublicKeyFile());
    assertFalse("The paths should not be the same.", fileName.equals(provider.getPublicKeyFile().getPath()));
    assertTrue("The paths should end the same.", provider.getPublicKeyFile().getPath().endsWith(fileName));
}

From source file:com.maxl.java.aips2xml.Aips2Xml.java

static void writeToFile(String string_to_write, String dir_name, String file_name) {
    try {/*from w  ww  .j  a v  a 2s  . c o m*/
        File wdir = new File(dir_name);
        if (!wdir.exists())
            wdir.mkdirs();
        File wfile = new File(dir_name + file_name);
        if (!wfile.exists())
            wfile.createNewFile();
        // FileWriter fw = new FileWriter(wfile.getAbsoluteFile());
        CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
        encoder.onMalformedInput(CodingErrorAction.REPORT);
        encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(wfile.getAbsoluteFile()), encoder);
        BufferedWriter bw = new BufferedWriter(osw);
        bw.write(string_to_write);
        bw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:lib.Global.java

@Override
public Configuration onLoadConfig(Configuration configuration, File file, ClassLoader classLoader) {
    boolean isTest = false;
    if (System.getProperty("skip.config.check", "false").equals("true")) {
        log.info("In test mode, not performing config file checks.");
        isTest = true;/*ww  w.  j a  v a 2s.  c  o m*/
    }
    final String configOverrideLocation = Tools.firstNonNull("", System.getProperty("config.file"),
            System.getProperty("config.url"), System.getProperty("config.resource"));
    if (!configOverrideLocation.isEmpty()) {
        log.warn("Using configuration from overridden location at {}", configOverrideLocation);
        return configuration;
    }

    final File configFile = new File(file, "conf/graylog-web-interface.conf");
    if (!isTest) {
        if (!configFile.exists()) {
            log.error("Your configuration should be at {} but does not exist, cannot continue without it.",
                    configFile.getAbsoluteFile());
            throw new IllegalStateException("Missing configuration file " + configFile.getAbsolutePath());
        } else if (!configFile.canRead()) {
            log.error("Your configuration at {} is not readable, cannot continue without it.",
                    configFile.getAbsoluteFile());
            throw new IllegalStateException("Unreadable configuration file " + configFile.getAbsolutePath());
        }
    }
    final Config config = ConfigFactory.parseFileAnySyntax(configFile);
    if (config.isEmpty() && !isTest) {
        log.error("Your configuration file at {} is empty, cannot continue without content.",
                configFile.getAbsoluteFile());
        throw new IllegalStateException("Empty configuration file " + configFile.getAbsolutePath());
        /*
         *
         * This is merging the standard bundled application.conf with our graylog-web-interface.conf.
         * The application.conf must always be empty when packaged so there is nothing hidden from the user.
         * We are merging, because the Configuration object already contains some information the web-interface needs.
         *
         */
    }
    return new Configuration(config.withFallback(configuration.getWrappedConfiguration().underlying()));
}

From source file:net.nicholaswilliams.java.licensing.encryption.TestFilePrivateKeyDataProvider.java

@Test
public void testKeyFile02() throws IOException {
    final String fileName = "testKeyFile02.key";
    File file = new File(fileName);

    if (file.exists())
        FileUtils.forceDelete(file);// w w  w .j  av  a 2 s . co  m

    FilePrivateKeyDataProvider provider = new FilePrivateKeyDataProvider(file);

    assertNotNull("The key file should not be null.", provider.getPrivateKeyFile());
    assertNotSame("The objects should not be the same.", file, provider.getPrivateKeyFile());
    assertEquals("The key file is not correct.", file.getAbsoluteFile(), provider.getPrivateKeyFile());
    assertFalse("The paths should not be the same.", fileName.equals(provider.getPrivateKeyFile().getPath()));
    assertTrue("The paths should end the same.", provider.getPrivateKeyFile().getPath().endsWith(fileName));
}

From source file:de.micromata.genome.util.runtime.CwdTest.java

@Test
public void testCwd() {
    String oldpwd = System.getProperty("user.dir");
    try {/*from  w  w  w .  j a  v  a2 s . c  o  m*/
        File curFile = new File("pom.xml");
        String pom1 = FileUtils.readFileToString(curFile, Charset.defaultCharset());
        // Ausgabe: ./pom.xml: C:\Users\roger\d\micromata\genome\genome-commons\pom.xml
        System.out.println("./pom.xml: " + curFile.getAbsolutePath());
        File parentDir = new File("./..");
        // setze user dir auf parent file
        System.setProperty("user.dir", parentDir.getCanonicalFile().getAbsolutePath());
        File pafile = new File("pom.xml");
        // das gibt den namen parent pom aus!!!!
        // Ausgabe: new cwd: (..)./pom.xml: C:\Users\roger\d\micromata\genome\pom.xml
        System.out.println("new cwd: (..)./pom.xml: " + pafile.getAbsolutePath());
        // !!!!!!
        // das liest trotzdem das pom1 aus!!!
        String pom2 = FileUtils.readFileToString(pafile, Charset.defaultCharset());
        Assert.assertEquals(pom1, pom2);
        // das fixt das: 
        File pafile2 = pafile.getAbsoluteFile();
        String pom3 = FileUtils.readFileToString(pafile2, Charset.defaultCharset());
        // jetzt tatsaechlich das parent pom
        Assert.assertNotEquals(pom1, pom3);
    } catch (IOException ex) {
        ex.printStackTrace();
        ;
    } finally {
        System.setProperty("user.dir", oldpwd);
    }
}