Example usage for java.io File getAbsolutePath

List of usage examples for java.io File getAbsolutePath

Introduction

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

Prototype

public String getAbsolutePath() 

Source Link

Document

Returns the absolute pathname string of this abstract pathname.

Usage

From source file:com.microsoft.tfs.client.common.ui.framework.diagnostics.InternalSupportUtils.java

public static void openFile(final File file) {
    Launcher.launch(file.getAbsolutePath());
}

From source file:msuresh.raftdistdb.AtomixDB.java

public static void delete(File path) throws FileNotFoundException {
    if (!path.exists())
        throw new FileNotFoundException(path.getAbsolutePath());
    for (File f : path.listFiles()) {
        f.delete();/* w  w w . j av a2 s.  c  o  m*/
    }

}

From source file:acromusashi.kafka.log.producer.util.YamlReadUtil.java

/**
 * ???Yaml????Yaml?/* w ww. j a  v  a  2  s .  c  om*/
 * 
 * @param filePath 
 * @return ???
 * @throws IOException 
 */
@SuppressWarnings({ "unchecked" })
public static Map<String, Object> readYaml(String filePath) throws IOException {
    Map<String, Object> configObject = null;
    Yaml yaml = new Yaml();

    InputStream inputStream = null;
    InputStreamReader steamReader = null;
    File file = new File(filePath);

    try {
        inputStream = new FileInputStream(file.getAbsolutePath());
        steamReader = new InputStreamReader(inputStream, "UTF-8");
        configObject = (Map<String, Object>) yaml.load(steamReader);
    } catch (Exception ex) {
        // ScannerException/IOException?????
        // 2???????????????Exception?????
        throw new IOException(ex);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }

    return configObject;
}

From source file:com.esri.geoportal.base.metadata.MetadataCLI.java

public static void testScriptEvaluator(File metadata, Boolean verbose) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    AppUser user = null;//from  w  w  w.  j  a v  a  2 s .c o  m
    boolean pretty = true;
    File p = metadata;
    String xml = XmlUtil.readFile(p.getAbsolutePath());
    MetadataDocument mdoc = new MetadataDocument();
    mdoc.setXml(xml);

    Evaluator jsEvaluator = new Evaluator();
    // add all files from directory
    //File[] files =  metadataPath.listFiles();
    //String jsPath = metadataPath.getPath() + "metadata/js/Evaluator.js";

    String jsPath = "metadata/js/Evaluator.js";
    jsEvaluator.setJavascriptFile(jsPath);
    //jsEvaluator.setJavascriptFile(metadataPath.getPath() + "IsoEvaluator.js");

    jsEvaluator.interrogate(mdoc);
    System.err.println("typeKey=" + mdoc.getMetadataType().getKey());
    System.err.println("detailsXslt=" + jsEvaluator.getDetailsXslt(mdoc.getMetadataType().getKey()));
    jsEvaluator.evaluate(mdoc);
    System.err.println("title=" + mdoc.getTitle());
    if (verbose) {
        System.err.println("xml=" + mdoc.getXml());
    }
    Object json = mapper.readValue(mdoc.getEvaluatedJson(), Object.class);
    String indented = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
    System.err.println("evaluatedjson=" + indented);

}

From source file:Main.java

public static void writeToExternalFile(String data, String logTag, String fileName) {

    if (!isExternalStorageWritable()) {
        Log.e(logTag, "failed to find external storage");
    } else {/*from   w ww.j  av  a  2  s. com*/
        File path = Environment.getExternalStorageDirectory();
        File dir = new File(path.getAbsolutePath() + "/SDNController");
        if (!dir.isDirectory()) {
            if (!dir.mkdirs()) {
                Log.e(logTag, "sdn directory can not be created");
                return;
            }
        }

        File file = new File(dir, fileName);
        try {
            FileOutputStream f = new FileOutputStream(file, true);
            PrintWriter pw = new PrintWriter(f);
            pw.println(data);
            pw.flush();
            pw.close();
            f.close();
        } catch (FileNotFoundException e) {
            Log.e(logTag, "can not find indicated file");
            e.printStackTrace();
        } catch (IOException e) {
            Log.e(logTag, "failed to write SDNController/result.txt");
            e.printStackTrace();
        }
    }
}

From source file:ch.unibas.fittingwizard.infrastructure.base.ScriptUtilities.java

public static void deleteFileIfExists(File resultsFile) {
    if (resultsFile.exists()) {
        logger.info("Deleting existing file. " + FilenameUtils.normalize(resultsFile.getAbsolutePath()));
        if (resultsFile.delete()) {
            logger.info("File deleted.");
        } else {// w  ww. j a v  a 2  s .  c o m
            logger.error("Could not delete file.");
        }
    }
}

From source file:com.jaspersoft.jasperserver.jrsh.common.ZipUtil.java

protected static void addFiles(ZipOutputStream zos, String folder, String baseFolder) throws Exception {
    File file = new File(folder);
    if (file.exists()) {
        if (file.isDirectory()) {
            if (!folder.equalsIgnoreCase(baseFolder)) {
                String entryName = folder.substring(baseFolder.length() + 1, folder.length()) + separatorChar;
                ZipEntry zipEntry = new ZipEntry(entryName);
                zos.putNextEntry(zipEntry);
            }/*from w  w w.  jav  a  2  s . co m*/
            File files[] = file.listFiles();
            if (files != null) {
                for (File f : files) {
                    addFiles(zos, f.getAbsolutePath(), baseFolder);
                }
            }
        } else {
            String entryName = folder.substring(baseFolder.length() + 1, folder.length());
            ZipEntry zipEntry = new ZipEntry(entryName);
            zos.putNextEntry(zipEntry);

            try (FileInputStream in = new FileInputStream(folder)) {
                int len;
                byte buf[] = new byte[1024];
                while ((len = in.read(buf)) > 0) {
                    zos.write(buf, 0, len);
                }
                zos.closeEntry();
            }
        }
    }
}

From source file:Main.java

public static String showOpenFile(String currentDirectoryPath, Component parent, final String filterRegex,
        final String filterDescription) {
    JFileChooser fileChooser = new JFileChooser(currentDirectoryPath);
    fileChooser.addChoosableFileFilter(new FileFilter() {
        private Pattern regexPattern = Pattern.compile(filterRegex);

        public boolean accept(File f) {
            if (f.isDirectory())
                return true;
            return regexPattern.matcher(f.getName()).matches();
        }//from  w w  w  .  ja v a 2  s . c o m

        public String getDescription() {
            return filterDescription;
        }

    });
    fileChooser.showOpenDialog(parent);

    File choosedFile = fileChooser.getSelectedFile();
    if (choosedFile == null)
        return null;
    return choosedFile.getAbsolutePath();
}

From source file:Main.java

public static int getExifRotation(File imageFile) {
    if (imageFile == null)
        return 0;
    try {/*w w w .  j av  a  2  s  .  c om*/
        ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
        // We only recognize a subset of orientation tag values
        switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            return 90;
        case ExifInterface.ORIENTATION_ROTATE_180:
            return 180;
        case ExifInterface.ORIENTATION_ROTATE_270:
            return 270;
        default:
            return ExifInterface.ORIENTATION_UNDEFINED;
        }
    } catch (IOException e) {
        return 0;
    }
}