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:mondrian.gui.Workbench.java

/**
 * @param args the command line arguments
 */// w ww  .  ja va  2 s. com
public static void main(String args[]) {
    Workbench w = null;
    try {
        w = new Workbench();
        w.parseArgs(args);
        w.setSize(800, 600);
        // if user specified a file to open, do so now.
        if (w.openFile != null) {
            File f = new File(w.openFile);
            if (f.canRead()) {
                w.openSchemaFrame(f.getAbsoluteFile(),
                        // parameter to indicate this is a new or existing
                        // catalog file
                        false);
            }
        }
        w.setVisible(true);
    } catch (Throwable ex) {
        if (w != null) {
            JOptionPane.showMessageDialog(w,
                    w.getResourceConverter().getFormattedString("workbench.main.uncoverable_error",
                            "Pentaho Schema Workbench has encountered an unrecoverable error. \n{0}",
                            ex.getLocalizedMessage()),
                    w.getResourceConverter().getString("workbench.main.uncoverable_error.title",
                            "PSW Fatal Error"),
                    JOptionPane.ERROR_MESSAGE);
        }
        LOGGER.error("main", ex);
    }
}

From source file:com.zarkonnen.longan.Main.java

public static void main(String[] args) throws IOException {
    // Use Apache Commons CLI (packaged into the Jar) to parse command line options.
    Options options = new Options();
    Option helpO = OptionBuilder.withDescription("print help").create("h");
    Option versionO = OptionBuilder.withDescription("print version").create("v");
    Option outputO = OptionBuilder.withDescription("output file").withLongOpt("out").hasArg()
            .withArgName("file").create("o");
    Option formatO = OptionBuilder
            .withDescription("output format: one of plaintext (default) and visualize (debug output in png)")
            .hasArg().withArgName("format").withLongOpt("format").create();
    Option serverO = OptionBuilder.withDescription("launches server mode: Server mode reads "
            + "command line strings one per line exactly as above. If no output file is "
            + "specified, returns a line containing the number of output lines before the "
            + "output. If there is an error, returns a single line with the error message. "
            + "Shut down server by sending \"quit\".").withLongOpt("server").create();
    Option openCLO = OptionBuilder
            .withDescription(//from  w ww. jav  a 2 s .c  o m
                    "enables use of the graphics card to " + "support the OCR system. Defaults to true.")
            .withLongOpt("enable-opencl").hasArg().withArgName("enabled").create();
    options.addOption(helpO);
    options.addOption(versionO);
    options.addOption(outputO);
    options.addOption(formatO);
    options.addOption(serverO);
    options.addOption(openCLO);
    CommandLineParser clp = new GnuParser();
    try {
        CommandLine line = clp.parse(options, args);
        if (line.hasOption("h")) {
            new HelpFormatter().printHelp(INVOCATION, options);
            System.exit(0);
        }
        if (line.hasOption("v")) {
            System.out.println(Longan.VERSION);
            System.exit(0);
        }
        boolean enableOpenCL = true;
        if (line.hasOption("enable-opencl")) {
            enableOpenCL = line.getOptionValue("enable-opencl").toLowerCase().equals("true")
                    || line.getOptionValue("enable-opencl").equals("1");
        }
        if (line.hasOption("server")) {
            Longan longan = Longan.getDefaultImplementation(enableOpenCL);
            BufferedReader inputR = new BufferedReader(new InputStreamReader(System.in));
            while (true) {
                String input = inputR.readLine();
                if (input.trim().equals("quit")) {
                    return;
                }
                String[] args2 = splitInput(input);
                Options o2 = new Options();
                o2.addOption(outputO);
                o2.addOption(formatO);
                try {
                    line = clp.parse(o2, args2);

                    File outFile = null;
                    if (line.hasOption("o")) {
                        outFile = new File(line.getOptionValue("o"));
                    }

                    ResultConverter format = FORMATS.get(line.getOptionValue("format", "plaintext"));
                    if (format != DEFAULT_FORMAT && outFile == null) {
                        System.out.println("You must specify an output file for non-plaintext output.");
                        continue;
                    }

                    if (line.getArgList().isEmpty()) {
                        System.out.println("Please specify an input image.");
                        continue;
                    }
                    if (line.getArgList().size() > 1) {
                        System.err.println("Please specify one input image at a time");
                        continue;
                    }

                    File inFile = new File((String) line.getArgList().get(0));

                    if (!inFile.exists()) {
                        System.out.println("The input image does not exist.");
                        continue;
                    }

                    try {
                        Result result = longan.process(ImageIO.read(inFile));
                        if (outFile == null) {
                            String txt = DEFAULT_FORMAT.convert(result);
                            System.out.println(numNewlines(txt) + 1);
                            System.out.print(txt);
                        } else {
                            if (outFile.getAbsoluteFile().getParentFile() != null
                                    && !outFile.getAbsoluteFile().getParentFile().exists()) {
                                outFile.getParentFile().mkdirs();
                            }
                            FileOutputStream fos = new FileOutputStream(outFile);
                            try {
                                format.write(result, fos);
                            } finally {
                                fos.close();
                            }
                        }
                    } catch (Exception e) {
                        System.out.println("Processing error: " + exception(e));
                    }
                } catch (ParseException e) {
                    System.out.println("Input not recognized: " + exception(e));
                }
            } // End server loop
        } else {
            // Single invocation
            File outFile = null;
            if (line.hasOption("o")) {
                outFile = new File(line.getOptionValue("o"));
            }

            ResultConverter format = FORMATS.get(line.getOptionValue("format", "plaintext"));
            if (format != DEFAULT_FORMAT && outFile == null) {
                System.err.println("You must specify an output file for non-plaintext output.");
                System.exit(1);
            }

            if (line.getArgList().isEmpty()) {
                System.err.println("Please specify an input image.");
                new HelpFormatter().printHelp(INVOCATION, options);
                System.exit(1);
            }
            if (line.getArgList().size() > 1) {
                System.err.println("Please specify one input image only. To process multiple "
                        + "images, use server mode.");
                System.exit(1);
            }
            File inFile = new File((String) line.getArgList().get(0));

            if (!inFile.exists()) {
                System.err.println("The input image does not exist.");
                System.exit(1);
            }

            try {
                Result result = Longan.getDefaultImplementation(enableOpenCL).process(ImageIO.read(inFile));
                if (outFile == null) {
                    String txt = DEFAULT_FORMAT.convert(result);
                    System.out.print(txt);
                } else {
                    if (outFile.getAbsoluteFile().getParentFile() != null
                            && !outFile.getAbsoluteFile().getParentFile().exists()) {
                        outFile.getParentFile().mkdirs();
                    }
                    FileOutputStream fos = new FileOutputStream(outFile);
                    try {
                        format.write(format.convert(result), fos);
                    } finally {
                        fos.close();
                    }
                }
            } catch (Exception e) {
                System.err.println("Processing error: " + exception(e));
                System.exit(1);
            }
        }
    } catch (ParseException e) {
        System.err.println("Parsing command line input failed: " + exception(e));
        System.exit(1);
    }
}

From source file:fll.scheduler.TableOptimizer.java

/**
 * @param args/*w ww  . jav a2s.  com*/
 */
public static void main(final String[] args) {
    LogUtils.initializeLogging();

    File schedfile = null;
    final Options options = buildOptions();
    try {
        final CommandLineParser parser = new PosixParser();
        final CommandLine cmd = parser.parse(options, args);

        schedfile = new File(cmd.getOptionValue(SCHED_FILE_OPTION));

    } catch (final org.apache.commons.cli.ParseException pe) {
        LOGGER.error(pe.getMessage());
        usage(options);
        System.exit(1);
    }

    FileInputStream fis = null;
    try {
        if (!schedfile.canRead()) {
            LOGGER.fatal(schedfile.getAbsolutePath() + " is not readable");
            System.exit(4);
        }

        final boolean csv = schedfile.getName().endsWith("csv");
        final CellFileReader reader;
        final String sheetName;
        if (csv) {
            reader = new CSVCellReader(schedfile);
            sheetName = null;
        } else {
            sheetName = SchedulerUI.promptForSheetName(schedfile);
            if (null == sheetName) {
                return;
            }
            fis = new FileInputStream(schedfile);
            reader = new ExcelCellReader(fis, sheetName);
        }

        final ColumnInformation columnInfo = TournamentSchedule.findColumns(reader, new LinkedList<String>());
        if (null != fis) {
            fis.close();
            fis = null;
        }

        final List<SubjectiveStation> subjectiveStations = SchedulerUI.gatherSubjectiveStationInformation(null,
                columnInfo);

        // not bothering to get the schedule params as we're just tweaking table
        // assignments, which wont't be effected by the schedule params.
        final SchedParams params = new SchedParams(subjectiveStations, SchedParams.DEFAULT_PERFORMANCE_MINUTES,
                SchedParams.MINIMUM_CHANGETIME_MINUTES, SchedParams.MINIMUM_PERFORMANCE_CHANGETIME_MINUTES);
        final List<String> subjectiveHeaders = new LinkedList<String>();
        for (final SubjectiveStation station : subjectiveStations) {
            subjectiveHeaders.add(station.getName());
        }

        final String name = Utilities.extractBasename(schedfile);

        final TournamentSchedule schedule;
        if (csv) {
            schedule = new TournamentSchedule(name, schedfile, subjectiveHeaders);
        } else {
            fis = new FileInputStream(schedfile);
            schedule = new TournamentSchedule(name, fis, sheetName, subjectiveHeaders);
        }

        final TableOptimizer optimizer = new TableOptimizer(params, schedule,
                schedfile.getAbsoluteFile().getParentFile());
        final long start = System.currentTimeMillis();
        optimizer.optimize(null);
        final long stop = System.currentTimeMillis();
        LOGGER.info("Optimization took: " + (stop - start) / 1000.0 + " seconds");

    } catch (final ParseException e) {
        LOGGER.fatal(e, e);
        System.exit(5);
    } catch (final ScheduleParseException e) {
        LOGGER.fatal(e, e);
        System.exit(6);
    } catch (final IOException e) {
        LOGGER.fatal("Error reading file", e);
        System.exit(4);
    } catch (final RuntimeException e) {
        LOGGER.fatal(e, e);
        throw e;
    } catch (InvalidFormatException e) {
        LOGGER.fatal(e, e);
        System.exit(7);
    } finally {
        try {
            if (null != fis) {
                fis.close();
            }
        } catch (final IOException e) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Error closing stream", e);
            }
        }
    }

}

From source file:Main.java

public static File getTempPath(File file) {
    File tempFile = new File(file.getAbsoluteFile() + ".tmp");
    return tempFile;
}

From source file:Main.java

public static boolean CustomerFileExists() {
    File f = new File(".");
    String FilePath = f.getAbsoluteFile().getParent() + "\\Customers.xml";
    f = new File(FilePath);
    return f.exists();
}

From source file:Main.java

public static String getLocalAbstractPath(File file) {
    return String.format("file://%s", file.getAbsoluteFile());
}

From source file:Main.java

public static void removeOldVersionFiles(Context context, String fileName) {
    File dataDirPath = new File(context.getApplicationInfo().dataDir);
    File[] fileList = dataDirPath.listFiles();

    for (File file : fileList) {
        if (file.getAbsoluteFile().toString().endsWith(fileName)) {
            file.delete();/*w  w  w . ja  v a  2 s.  c om*/
        }
    }
}

From source file:Main.java

/**
 * Construct a File for an xxxx.jpg image in the external storage directory
 * /*from  w  ww  . jav a  2 s .c  o m*/
 * @param name
 *            the 'xxxx'
 * @return File
 */
public static File constructExternalImageFile(String name) {
    File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    File imageFile = new File(storageDir, name + JPEG_EXTENSION);
    imageFile = imageFile.getAbsoluteFile();
    return imageFile;
}

From source file:Main.java

private static void SaveCustomerFile(Document CustomerDoc, JFrame mainFrame) {
    try {//from w w  w . ja  v  a 2s .c o m
        TransformerFactory Factory = TransformerFactory.newInstance();
        Transformer Trans = Factory.newTransformer();
        DOMSource source = new DOMSource(CustomerDoc);
        File f = new File(".");
        String FilePath = f.getAbsoluteFile().getParent() + "\\Customers.xml";
        f = new File(FilePath);
        if (f.exists()) {
            f.delete();
        }
        StreamResult Result = new StreamResult(f);
        Trans.setOutputProperty(OutputKeys.INDENT, "yes");
        Trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "7");
        Trans.transform(source, Result);
    } catch (TransformerException ex) {
        System.out.println(ex.getMessage());
        JOptionPane.showMessageDialog(mainFrame,
                "There Was an Error Saving The File. Please Restart the Application.");
        System.exit(1);
    }
}

From source file:com.ltb.Main.java

public static void displayIt(File node) throws IOException, InterruptedException {
    String filePath = node.getAbsoluteFile().getAbsolutePath();
    System.out.println(filePath);

    if (node.isDirectory()) {
        String[] subNote = node.list();
        for (String filename : subNote) {
            displayIt(new File(node, filename));
        }/*w  w w . ja v a 2s. c om*/
    } else {

        //Process pr = Runtime.getRuntime().exec("avconv -i //home//juanma//Videos//License.avi"); // Working fine
        //Process pr = Runtime.getRuntime().exec(outLine); // Working fine without spaces
        String[] args1 = { "avconv", "-i", filePath };
        Process pr = Runtime.getRuntime().exec(args1);
        //filePath = filePath.replace("/" , "//");
        //filePath = filePath.replace(" " , "\\ ");
        //String commandline ="avconv -i \""+filePath+"\"";
        //String commandline ="avconv -i "+filePath;
        //Process pr = Runtime.getRuntime().exec(commandline);

        BufferedReader in = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
        //BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
        String line;
        // Start FilmFactory
        String extension = FilenameUtils.getExtension(node.getName());
        if (isFilmExtension(extension) == false) {
            return;
        } else {

            Film film = new Film(node.getName(), filePath);
            while ((line = in.readLine()) != null) {
                System.out.println(line);
                if (line.contains("Invalid data")) {
                    // TODO Most probably no film - Change method below
                    film.isNotFilm();
                } else if (line.contains("Audio")) {
                    film.addAudioTrack(line);
                } else if (line.contains("No such file")) {
                    System.out.println("Error?");
                }

            }
            pr.waitFor();
            in.close();
        }
    }

}