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:Main.java

public static void main(String[] argv) throws Exception {

    File file = new File("filename.txt");
    file = file.getAbsoluteFile();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    File file = new File("dir" + File.separatorChar + "filename.txt");
    file = file.getAbsoluteFile();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    File file = new File(".." + File.separatorChar + "filename.txt");
    file = file.getAbsoluteFile();

}

From source file:MainClass.java

public static void main(String[] a) {
    File myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator, "File.java");
    System.out.println(myFile.getAbsoluteFile());
}

From source file:org.jasig.portlet.data.Importer.java

public static void main(String[] args) throws Exception {
    String dir = args[0];/* w w  w  . ja va 2 s .  c  om*/
    String importExportContext = args[1];
    String sessionFactoryBeanName = args[2];
    String modelClassName = args[3];
    String serviceBeanName = args[4];
    String serviceBeanMethodName = args[5];

    ApplicationContext context = PortletApplicationContextLocator.getApplicationContext(importExportContext);
    SessionFactory sessionFactory = context.getBean(sessionFactoryBeanName, SessionFactory.class);
    Class<?> modelClass = Class.forName(modelClassName);
    Object service = context.getBean(serviceBeanName);

    JAXBContext jc = JAXBContext.newInstance(modelClass);

    File folder = new File(dir);
    File[] files = folder.listFiles(new ImportFileFilter());

    for (File f : files) {
        StreamSource xml = new StreamSource(f.getAbsoluteFile());
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        JAXBElement je1 = unmarshaller.unmarshal(xml, modelClass);
        Object object = je1.getValue();
        Session session = sessionFactory.getCurrentSession();
        Transaction transaction = session.beginTransaction();

        Method method = service.getClass().getMethod(serviceBeanMethodName, modelClass);
        method.invoke(service, object);
        transaction.commit();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File f = new File("test.txt");

    // create new file in the system
    f.createNewFile();/*from ww  w .  j a v  a  2s. c  o  m*/

    // create new file object from the absolute path
    File f1 = f.getAbsoluteFile();

    System.out.println(f1);

}

From source file:com.blogspot.devsk.l2j.geoconv.GeoGonv.java

public static void main(String[] args) {

    if (args == null || args.length == 0) {
        System.out.println("File name was not specified, [\\d]{1,2}_[\\d]{1,2}.txt will be used");
        args = new String[] { "[\\d]{1,2}_[\\d]{1,2}.txt" };
    }/*  ww w  .ja va  2s . c o m*/

    File dir = new File(".");
    File[] files = dir.listFiles((FileFilter) new RegexFileFilter(args[0]));

    ArrayList<File> checked = new ArrayList<File>();
    for (File file : files) {
        if (file.isDirectory() || file.isHidden() || !file.exists()) {
            System.out.println(file.getAbsoluteFile() + " was ignored.");
        } else {
            checked.add(file);
        }
    }

    if (OUT_DIR.exists() && OUT_DIR.isDirectory() && OUT_DIR.listFiles().length > 0) {
        try {
            System.out.println("Directory with generated files allready exists, making backup...");
            FileUtils.moveDirectory(OUT_DIR, new File("generated-backup-" + System.currentTimeMillis()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    if (!OUT_DIR.exists()) {
        OUT_DIR.mkdir();
    }

    for (File file : checked) {
        GeoConvThreadFactory.startThread(new ParseTask(file));
    }
}

From source file:GuaranteeAFile.java

public static void main(String[] args) {

    String filename = "C:/myFile.txt";
    File aFile = new File(filename);
    if (aFile.isDirectory()) {
        System.out.println("The path " + aFile.getPath() + " does not specify a file. Program aborted.");
        System.exit(1);/*from  w w w.  j  a va  2s .c o m*/
    }
    if (!aFile.isFile()) {
        aFile = aFile.getAbsoluteFile();
        File parentDir = new File(aFile.getParent());
        if (!parentDir.exists()) {
            parentDir.mkdirs();
        }
    }
    FileOutputStream outputFile = null;
    try {
        outputFile = new FileOutputStream(aFile, true);
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
    }
}

From source file:lu.tudor.santec.dicom.gui.header.Dcm2Xml.java

public static void main(String[] args) {
    CommandLine cl = parse(args);//from  ww w.j  av a2 s  . com
    Dcm2Xml dcm2xml = new Dcm2Xml();
    File ifile = new File((String) cl.getArgList().get(0));
    File ofile = null;
    if (cl.hasOption("o")) {
        ofile = new File(cl.getOptionValue("o"));
        dcm2xml.setBaseDir(ofile.getAbsoluteFile().getParentFile());
    }
    if (cl.hasOption("d")) {
        dcm2xml.setBaseDir(new File(cl.getOptionValue("d")));
    }
    boolean x = cl.hasOption("X");
    if (cl.hasOption("x")) {
        String[] tagStr = cl.getOptionValues("x");
        int[] excludes = new int[x ? tagStr.length + 1 : tagStr.length];
        for (int i = 0; i < tagStr.length; i++) {
            try {
                excludes[i] = (int) Long.parseLong(tagStr[i], 16);
            } catch (NumberFormatException e) {
                excludes[i] = Tag.forName(tagStr[i]);
            }
        }
        if (x) {
            excludes[tagStr.length] = Tag.PixelData;
        }
        dcm2xml.setExclude(excludes);
    } else if (x) {
        dcm2xml.setExclude(new int[] { Tag.PixelData });
    }
    if (cl.hasOption("T")) {
        final String xslurl = cl.getOptionValue("T");
        try {
            dcm2xml.setXslt(new URL(xslurl));
        } catch (MalformedURLException e) {
            System.err.println("dcm2xml: invalid xsl URL: " + xslurl);
            System.exit(1);
        }
        dcm2xml.setXsltInc(cl.hasOption("I"));
        dcm2xml.setXsltParams(cl.getOptionValues("P"));
    }
    dcm2xml.setComments(cl.hasOption("C"));
    dcm2xml.setIndent(!cl.hasOption("c"));
    long t1 = System.currentTimeMillis();
    try {
        dcm2xml.convert(ifile, ofile);
    } catch (TransformerConfigurationException e) {
        System.err.println("dcm2xml: Configuration Error: " + e.getMessage());
        System.exit(1);
    } catch (IOException e) {
        System.err.println("dcm2xml: Failed to convert " + ifile + ": " + e.getMessage());
        e.printStackTrace(System.err);
        System.exit(1);
    }
    long t2 = System.currentTimeMillis();
    if (ofile != null)
        System.out.println("Finished conversion of " + ifile + "to " + ofile + " in " + (t2 - t1) + "ms");
}

From source file:at.spardat.xma.xdelta.JarPatcher.java

/**
 * Main method to make {@link #applyDelta(ZipFile, ZipFile, ZipArchiveOutputStream, BufferedReader)} available at
 * the command line.<br>/*from   w  ww. j av  a 2s .  c o  m*/
 * usage JarPatcher source patch output
 *
 * @param args the arguments
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void main(String[] args) throws IOException {
    String patchName = null;
    String outputName = null;
    String sourceName = null;
    if (args.length == 0) {
        System.err.println("usage JarPatcher patch [output [source]]");
        System.exit(1);
    } else {
        patchName = args[0];
        if (args.length > 1) {
            outputName = args[1];
            if (args.length > 2) {
                sourceName = args[2];
            }
        }
    }
    ZipFile patch = new ZipFile(patchName);
    ZipArchiveEntry listEntry = patch.getEntry("META-INF/file.list");
    if (listEntry == null) {
        System.err.println("Invalid patch - list entry 'META-INF/file.list' not found");
        System.exit(2);
    }
    BufferedReader list = new BufferedReader(new InputStreamReader(patch.getInputStream(listEntry)));
    String next = list.readLine();
    if (sourceName == null) {
        sourceName = next;
    }
    next = list.readLine();
    if (outputName == null) {
        outputName = next;
    }
    int ignoreSourcePaths = Integer.parseInt(System.getProperty("patcher.ignoreSourcePathElements", "0"));
    int ignoreOutputPaths = Integer.parseInt(System.getProperty("patcher.ignoreOutputPathElements", "0"));
    Path sourcePath = Paths.get(sourceName);
    Path outputPath = Paths.get(outputName);
    if (ignoreOutputPaths >= outputPath.getNameCount()) {
        patch.close();
        StringBuilder b = new StringBuilder().append("Not enough path elements to ignore in output (")
                .append(ignoreOutputPaths).append(" in ").append(outputName).append(")");
        throw new IOException(b.toString());
    }
    if (ignoreSourcePaths >= sourcePath.getNameCount()) {
        patch.close();
        StringBuilder b = new StringBuilder().append("Not enough path elements to ignore in source (")
                .append(sourcePath).append(" in ").append(sourceName).append(")");
        throw new IOException(b.toString());
    }
    sourcePath = sourcePath.subpath(ignoreSourcePaths, sourcePath.getNameCount());
    outputPath = outputPath.subpath(ignoreOutputPaths, outputPath.getNameCount());
    File sourceFile = sourcePath.toFile();
    File outputFile = outputPath.toFile();
    if (!(outputFile.getAbsoluteFile().getParentFile().mkdirs()
            || outputFile.getAbsoluteFile().getParentFile().exists())) {
        patch.close();
        throw new IOException("Failed to create " + outputFile.getAbsolutePath());
    }
    new JarPatcher(patchName, sourceFile.getName()).applyDelta(patch, new ZipFile(sourceFile),
            new ZipArchiveOutputStream(new FileOutputStream(outputFile)), list);
    list.close();
}