Example usage for java.io File getCanonicalPath

List of usage examples for java.io File getCanonicalPath

Introduction

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

Prototype

public String getCanonicalPath() throws IOException 

Source Link

Document

Returns the canonical pathname string of this abstract pathname.

Usage

From source file:org.solrsystem.Main.java

public static void main(String[] args) throws IOException, HttpException {

    if (GraphicsEnvironment.isHeadless()) {
        UI = new TextInstall();
    } else {//from www  .jav  a2 s .c o  m
        UI = new GraphicalInstall();
    }

    if (UI.confirm("Do you want to create ./SolrSystem in this directory and install SolrSystem?")) {
        File solrSystemDir = new File("SolrSystem");
        //noinspection ResultOfMethodCallIgnored
        solrSystemDir.mkdir();
        UI.downLoad(GRADLE);

        File file = new File(solrSystemDir, "gradle-1.11-bin.zip");
        if (!file.exists()) {
            doGetToFile(GRADLE, file.getCanonicalPath(), UI);
        }
    }

}

From source file:FindDirectories.java

public static void main(String[] args) {
    // if no arguments provided, start at the parent directory
    if (args.length == 0)
        args = new String[] { ".." };

    try {/*from w ww . j  ava2  s. c  o m*/
        File pathName = new File(args[0]);
        String[] fileNames = pathName.list();

        // enumerate all files in the directory
        for (int i = 0; i < fileNames.length; i++) {
            File f = new File(pathName.getPath(), fileNames[i]);

            // if the file is again a directory, call the main method recursively
            if (f.isDirectory()) {
                System.out.println(f.getCanonicalPath());
                main(new String[] { f.getPath() });
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.kynetx.RubyRulesetParser.java

public static void main(String[] args) throws Exception {
    File thefile = new File(args[0]);
    String result_type = args[1];

    try {//w  w w  .  j  a va 2 s .  c o m
        ANTLRFileStream input = new ANTLRFileStream(thefile.getCanonicalPath());
        com.kynetx.RuleSetLexer lexer = new com.kynetx.RuleSetLexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        com.kynetx.RuleSetParser parser = new com.kynetx.RuleSetParser(tokens);
        parser.ruleset();
        JSONObject js = new JSONObject(parser.rule_json);
        if (result_type.equals("validate")) {
            if (parser.parse_errors.size() > 0) {
                for (int ii = 0; ii < parser.parse_errors.size(); ii++) {
                    System.out.println("ERROR: " + parser.parse_errors.get(ii));
                }
            }
        } else {
            System.out.println(js.toString());
            //                  System.out.println(unescapeUnicode(js.toString()));
        }
    } catch (Exception e) {
        System.out.println("SYSTEM ERROR : " + e.getMessage());
    }

}

From source file:com.cisco.dbds.utils.configfilehandler.FeatureFileRead_Testcase.java

/**
 * The main method.//w ww . j  a  v  a2s.co m
 *
 * @param args the arguments
 * @throws SocketException the socket exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void main(String args[]) throws SocketException, IOException {

    if (!rfile.exists()) {
        rfile.createNewFile();
    }
    fw = new FileWriter(rfile.getAbsoluteFile());
    bw = new BufferedWriter(fw);

    File dir = new File("C:\\TIMS");
    String[] extensions = new String[] { "feature" };

    System.out.println(
            "Getting all .feature files in " + dir.getCanonicalPath() + " including those in subdirectories");
    List<File> files = (List<File>) FileUtils.listFiles(dir, extensions, true);
    for (File file : files) {
        System.out.println("file: " + file.getCanonicalPath());
        readFeature(file.getCanonicalPath());
    }
    bw.close();

}

From source file:FileDemo.java

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

    // Display constants
    System.out.println("pathSeparatorChar = " + File.pathSeparatorChar);
    System.out.println("separatorChar = " + File.separatorChar);

    // Test some methods
    File file = new File(args[0]);
    System.out.println("getName() = " + file.getName());
    System.out.println("getParent() = " + file.getParent());
    System.out.println("getAbsolutePath() = " + file.getAbsolutePath());
    System.out.println("getCanonicalPath() = " + file.getCanonicalPath());
    System.out.println("getPath() = " + file.getPath());
    System.out.println("canRead() = " + file.canRead());
    System.out.println("canWrite() = " + file.canWrite());
}

From source file:PlyBounder.java

public static void main(String[] args) {

    // Get the commandline arguments
    Options options = new Options();
    // Available options
    Option plyPath = OptionBuilder.withArgName("dir").hasArg()
            .withDescription("directory containing input .ply files").create("plyPath");
    Option boundingbox = OptionBuilder.withArgName("string").hasArg()
            .withDescription("bounding box in WKT notation").create("boundingbox");
    Option outputPlyFile = OptionBuilder.withArgName("file").hasArg().withDescription("output PLY file name")
            .create("outputPlyFile");
    options.addOption(plyPath);//from   w  w w . ja va  2  s.  c om
    options.addOption(boundingbox);
    options.addOption(outputPlyFile);

    String plydir = ".";
    String boundingboxstr = "";
    String outputfilename = "";

    CommandLineParser parser = new DefaultParser();
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        boundingboxstr = line.getOptionValue("boundingbox");
        outputfilename = line.getOptionValue("outputPlyFile");

        if (line.hasOption("plyPath")) {
            // print the value of block-size
            plydir = line.getOptionValue("plyPath");
            System.out.println("Using plyPath=" + plydir);
        } else {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("PlyBounder", options);
        }
        //System.out.println( "plyPath=" + line.getOptionValue( "plyPath" ) );
    } catch (ParseException exp) {
        System.err.println("Error getting arguments: " + exp.getMessage());
    }

    // input directory
    // Get list of files
    File dir = new File(plydir);

    //System.out.println("Getting all files in " + dir.getCanonicalPath());
    List<File> files = (List<File>) FileUtils.listFiles(dir, new String[] { "ply", "PLY" }, false);
    for (File file : files) {
        try {
            System.out.println("file=" + file.getCanonicalPath());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    String sometempfile = "magweg.wkt";
    String s = null;

    // Loop through .ply files in directory
    for (File file : files) {
        try {
            String cmdl[] = { "./ply-tool.py", "intersection", file.getCanonicalPath(), boundingboxstr,
                    sometempfile };
            //System.out.println("Running: " + Arrays.toString(cmdl));
            Process p = Runtime.getRuntime().exec(cmdl);

            BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

            BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

            // read the output from the command
            System.out.println("cmdout:\n");
            while ((s = stdInput.readLine()) != null) {
                System.out.println(s);
            }

            // read any errors from the attempted command
            System.out.println("cmderr:\n");
            while ((s = stdError.readLine()) != null) {
                System.out.println(s);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Write new .ply file
    //ply-tool write setfile outputPlyFile
    try {
        String cmdl = "./ply-tool.py write " + sometempfile + " " + outputfilename;
        System.out.println("Running: " + cmdl);
        Process p = Runtime.getRuntime().exec(cmdl);

        BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

        BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

        // read the output from the command
        System.out.println("cmdout:\n");
        while ((s = stdInput.readLine()) != null) {
            System.out.println(s);
        }

        // read any errors from the attempted command
        System.out.println("cmderr:\n");
        while ((s = stdError.readLine()) != null) {
            System.out.println(s);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    // Done
    System.out.println("Done");
}

From source file:it.tidalwave.imageio.example.stats.FocalLengthStats.java

public static void main(final String[] args) {
    try {/*w w  w .j  a  v  a2s . com*/
        final PrintWriter out = new PrintWriter(new File(args[1]));
        new DirectoryWalker() {
            @Override
            protected void handleFile(final File file, final int depth, final Collection results)
                    throws IOException {
                if (file.getName().toUpperCase().endsWith(".NEF")) {
                    System.out.printf("Processing %s...\n", file.getCanonicalPath());
                    final ImageReader reader = (ImageReader) ImageIO.getImageReaders(file).next();
                    reader.setInput(ImageIO.createImageInputStream(file));
                    final IIOMetadata metadata = reader.getImageMetadata(0);
                    final NEFMetadata nefMetadata = (NEFMetadata) metadata;
                    final IFD exifIFD = nefMetadata.getExifIFD();
                    final TagRational focalLength = exifIFD.getFocalLength();
                    out.println(focalLength.doubleValue());
                }
            }

            public void start() throws IOException {
                super.walk(new File(args[0]), new ArrayList<Object>());
            }
        }.start();

        out.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:image.writer.ImageWriterExample2.java

/**
 * Command-line interface//ww  w .  ja  va 2 s .co  m
 * @param args command-line arguments
 */
public static void main(String[] args) {
    try {
        File targetDir;
        if (args.length >= 1) {
            targetDir = new File(args[0]);
        } else {
            targetDir = new File(".");
        }
        if (!targetDir.exists()) {
            System.err.println("Target Directory does not exist: " + targetDir);
        }
        File outputFile = new File(targetDir, "eps-example2.tif");
        ImageWriterExample2 app = new ImageWriterExample2();
        app.generateBitmapUsingJava2D(outputFile, "image/tiff");
        System.out.println("File written: " + outputFile.getCanonicalPath());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:image.writer.ImageWriterExample1.java

/**
 * Command-line interface//from   w  w w .  j a v a2  s  .  c om
 * @param args command-line arguments
 */
public static void main(String[] args) {
    try {
        File targetDir;
        if (args.length >= 1) {
            targetDir = new File(args[0]);
        } else {
            targetDir = new File(".");
        }
        if (!targetDir.exists()) {
            System.err.println("Target Directory does not exist: " + targetDir);
        }
        File outputFile = new File(targetDir, "eps-example1.tif");
        ImageWriterExample1 app = new ImageWriterExample1();
        app.generateBitmapUsingJava2D(outputFile, "image/tiff");
        System.out.println("File written: " + outputFile.getCanonicalPath());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.github.rnewson.couchdb.lucene.Main.java

/**
 * Run couchdb-lucene.//  w  ww.  j a v  a 2s  .  c om
 */
public static void main(String[] args) throws Exception {
    final HierarchicalINIConfiguration configuration = new HierarchicalINIConfiguration(
            Main.class.getClassLoader().getResource("couchdb-lucene.ini"));
    configuration.setReloadingStrategy(new FileChangedReloadingStrategy());

    final File dir = new File(configuration.getString("lucene.dir", "indexes"));

    if (dir == null) {
        LOG.error("lucene.dir not set.");
        System.exit(1);
    }
    if (!dir.exists() && !dir.mkdir()) {
        LOG.error("Could not create " + dir.getCanonicalPath());
        System.exit(1);
    }
    if (!dir.canRead()) {
        LOG.error(dir + " is not readable.");
        System.exit(1);
    }
    if (!dir.canWrite()) {
        LOG.error(dir + " is not writable.");
        System.exit(1);
    }
    LOG.info("Index output goes to: " + dir.getCanonicalPath());

    final Server server = new Server();
    final SelectChannelConnector connector = new SelectChannelConnector();
    connector.setHost(configuration.getString("lucene.host", "localhost"));
    connector.setPort(configuration.getInt("lucene.port", 5985));

    LOG.info("Accepting connections with " + connector);

    server.setConnectors(new Connector[] { connector });
    server.setStopAtShutdown(true);
    server.setSendServerVersion(false);

    HttpClientFactory.setIni(configuration);
    final HttpClient httpClient = HttpClientFactory.getInstance();

    final LuceneServlet servlet = new LuceneServlet(httpClient, dir, configuration);

    final Context context = new Context(server, "/", Context.NO_SESSIONS | Context.NO_SECURITY);
    context.addServlet(new ServletHolder(servlet), "/*");
    context.addFilter(new FilterHolder(new GzipFilter()), "/*", Handler.DEFAULT);
    context.setErrorHandler(new JSONErrorHandler());
    server.setHandler(context);

    server.start();
    server.join();
}