Example usage for java.io File exists

List of usage examples for java.io File exists

Introduction

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

Prototype

public boolean exists() 

Source Link

Document

Tests whether the file or directory denoted by this abstract pathname exists.

Usage

From source file:fr.jamgotchian.tuplegen.core.Main.java

public static void main(String[] args) {
    CommandLineParser parser = new PosixParser();

    try {/*from  w  w w.  j a  v  a  2  s.co m*/
        CommandLine line = parser.parse(OPTIONS, args);
        if (line.hasOption("h") || !line.hasOption("c") || !line.hasOption("d")) {
            usage();
        }
        File genSrcDir = new File(line.getOptionValue("d"));
        if (!genSrcDir.exists()) {
            throw new IllegalArgumentException(genSrcDir + " does not exit");
        }
        if (!genSrcDir.isDirectory()) {
            throw new IllegalArgumentException(genSrcDir + " should be a directory");
        }
        File cfgFile = new File(line.getOptionValue("c"));
        if (!cfgFile.exists()) {
            throw new IllegalArgumentException(cfgFile + " does not exist");
        }
        TupleGen generator = new TupleGen();
        generator.generate(cfgFile, genSrcDir, false, LOGGER);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:b2s.idea.mavenize.App.java

public static void main(String... args) throws ParseException {
    Options options = new Options();
    options.addOption("i", "idea-dir", true, "Path to root directory of an intellij instance");
    options.addOption("o", "output-dir", true, "Path to put the newly created jar");

    if (args.length == 0) {
        error("", options);
        return;//w w w  . j  av a  2 s .  co  m
    }

    PosixParser parser = new PosixParser();
    CommandLine commandLine = parser.parse(options, args);

    if (commandLine.hasOption("i")) {
        String ideaDirValue = commandLine.getOptionValue("i");
        File ideaFolder = new File(ideaDirValue);
        if (!ideaFolder.exists()) {
            error("This path [" + ideaDirValue + "] can not be found", options);
            return;
        }

        File libFolder = new File(ideaFolder, "lib");
        if (!libFolder.exists()) {
            error("The [lib] folder was not found in the IDEA folder", options);
            return;
        }

        if (commandLine.hasOption("output-dir")) {
            File output = new File(commandLine.getOptionValue("output-dir"), determineFilename(ideaFolder));
            jarCombiner.combineAllJarsIn(libFolder, output);
            System.out.println("Combined Jar: " + output);
        } else {
            error("Please provide an output directory", options);
        }
    } else {
        error("Please provide the IDEA directory path", options);
    }
}

From source file:eu.qualimaster.easy.extension.debug.DebugProfile.java

/**
 * Executes the test.//from  ww  w  .ja  va 2 s.c o  m
 * 
 * @param args the first argument shall be the model location
 * @throws ModelManagementException in case that obtaining the models fails
 * @throws IOException if file operations fail
 */
public static void main(String[] args) throws ModelManagementException, IOException {
    if (0 == args.length) {
        System.out.println("qualimaster.profile: <model location>");
        System.exit(0);
    } else {
        Properties prop = new Properties();
        prop.put(CoordinationConfiguration.PIPELINE_ELEMENTS_REPOSITORY,
                "https://projects.sse.uni-hildesheim.de/qm/maven/");
        CoordinationConfiguration.configure(prop, false);
        File tmp = new File(FileUtils.getTempDirectory(), "qmDebugProfile");
        FileUtils.deleteDirectory(tmp);
        tmp.mkdirs();

        File modelLocation = new File(args[0]);
        if (!modelLocation.exists()) {
            System.out.println("model location " + modelLocation + " does not exist");
            System.exit(0);
        }
        initialize();
        ModelInitializer.registerLoader(ProgressObserver.NO_OBSERVER);
        ModelInitializer.addLocation(modelLocation, ProgressObserver.NO_OBSERVER);
        Project project = RepositoryHelper.obtainModel(VarModel.INSTANCE, "QM", null);

        // create descriptor before clearing the location - in infrastructure pass vil directly/resolve VIL
        Configuration monConfig = RepositoryHelper.createConfiguration(project, "MONITORING");
        QmProjectDescriptor source = new QmProjectDescriptor(tmp);
        try {
            ProfileData data = AlgorithmProfileHelper.createProfilePipeline(monConfig, "ProfileTestPip",
                    "fCorrelationFinancial", "TopoSoftwareCorrelationFinancial", source);
            //                  "fPreprocessor", "Preprocessor", source);
            System.out.println("Creation successful. " + data.getPipeline());
        } catch (VilException e) {
            e.printStackTrace();
        }
        ModelInitializer.removeLocation(modelLocation, ProgressObserver.NO_OBSERVER);
    }
}

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" };
    }// w w  w  .j  av  a  2 s.  c om

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

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

    // create new files
    File f = new File("test.txt");

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

    // tests if file exists
    boolean bool = f.exists();

    System.out.println("File exists: " + bool);

}

From source file:org.duracloud.account.db.util.DbUtilDriver.java

public static void main(String[] args) throws IOException {
    if (args.length != 2) {
        usage("Two arguments are required, you supplied: " + args.length);
        System.exit(1);//from ww w.  j  a  v  a 2  s . c o m
    }

    DbUtil.COMMAND command = null;
    String commandArg = args[0];
    if (commandArg.equalsIgnoreCase(DbUtil.COMMAND.PUT.name())) {
        command = DbUtil.COMMAND.PUT;
    } else {
        usage("The first argument must PUT. " + "The previously supported command GET and CLEAR "
                + "have been removed since the move to MC 2.0.0 " + "You supplied: " + commandArg);
        System.exit(1);
    }

    File workDir = new File(args[1]);
    if (!workDir.exists()) {
        usage("The work directory must exist: " + workDir.getPath());
        System.exit(1);
    } else if (!workDir.isDirectory()) {
        usage("The work directory must be a directory: " + workDir.getPath());
        System.exit(1);
    }

    ApplicationContext context = new ClassPathXmlApplicationContext("jpa-config.xml");
    DuracloudRepoMgr repoMgr = context.getBean("repoMgr", DuracloudRepoMgr.class);

    DbUtil dbUtil = new DbUtil(repoMgr, workDir);
    dbUtil.runCommand(command);
}

From source file:com.msbmsb.genealogeo.ui.cli.GenealoGeoCLI.java

/**
 * Command-line interface//  ww  w .java  2s  .  c  o  m
 */
public static void main(String[] args) throws Exception {
    GenealoGeoCLI cli = new GenealoGeoCLI();

    // parse command line
    String inputFileName = "";
    try {
        CommandLineParser parser = new GnuParser();
        CommandLine cl = parser.parse(cli.opts, args);
        inputFileName = cl.getOptionValue("file");
        if (cl.hasOption("help"))
            throw new ParseException(null);
    } catch (ParseException e) {
        cli.usage(e.getMessage());
    }

    // require an input file
    if (inputFileName == null) {
        cli.usage("Error: No input file given.");
    }

    // verify and load the input file
    File inputFile = new File(inputFileName);
    if (!inputFile.exists()) {
        cli.usage("Error: Could not open input file: " + inputFileName);
    }

    cli.load(inputFile);

    //  testing functions
    cli.genealoGeo.printFamilies();
    cli.genealoGeo.printLocations();
}

From source file:cmd.freebase2rdf.java

public static void main(String[] args) throws Exception {
    if (args.length != 2) {
        usage();/* ww  w . ja  v a2  s  .c o m*/
    }
    File input = new File(args[0]);
    if (!input.exists())
        error("File " + input.getAbsolutePath() + " does not exist.");
    if (!input.canRead())
        error("Cannot read file " + input.getAbsolutePath());
    if (!input.isFile())
        error("Not a file " + input.getAbsolutePath());
    File output = new File(args[1]);
    if (output.exists())
        error("Output file " + output.getAbsolutePath()
                + " already exists, this program do not override existing files.");
    if (output.canWrite())
        error("Cannot write file " + output.getAbsolutePath());
    if (output.isDirectory())
        error("Not a file " + output.getAbsolutePath());
    if (!output.getName().endsWith(".nt.gz"))
        error("Output filename should end with .nt.gz, this is the only format supported.");

    BufferedReader in = new BufferedReader(
            new InputStreamReader(new BZip2CompressorInputStream(new FileInputStream(input))));
    BufferedOutputStream out = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(output)));
    String line;

    ProgressLogger progressLogger = new ProgressLogger(log, "lines", 100000, 1000000);
    progressLogger.start();
    Freebase2RDF freebase2rdf = null;
    try {
        freebase2rdf = new Freebase2RDF(out);
        while ((line = in.readLine()) != null) {
            freebase2rdf.send(line);
            progressLogger.tick();
        }
    } finally {
        if (freebase2rdf != null)
            freebase2rdf.close();
    }
    print(log, progressLogger);
}

From source file:com.comcast.cdn.traffic_control.traffic_router.core.TrafficRouterStart.java

public static void main(String[] args) throws Exception {
    System.setProperty("deploy.dir", "src/test");
    System.setProperty("dns.zones.dir", "src/test/var/auto-zones");

    LogManager.getLogger("org.eclipse.jetty").setLevel(Level.WARN);
    LogManager.getLogger("org.springframework").setLevel(Level.WARN);

    ConsoleAppender consoleAppender = new ConsoleAppender(new PatternLayout("%d{ISO8601} [%-5p] %c{4}: %m%n"));
    LogManager.getRootLogger().addAppender(consoleAppender);
    LogManager.getRootLogger().setLevel(Level.INFO);

    File webAppDirectory = new File("src/main/webapp");
    if (!webAppDirectory.exists()) {
        LogManager.getRootLogger().fatal(webAppDirectory.getAbsolutePath()
                + " does not exist, are you running TrafficRouterStart from the correct directory?");
        System.exit(1);/*from   w w w .  j a  v  a2  s . c  om*/
    }

    int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(timeout);
    connector.setSoLingerTime(-1);
    connector.setPort(8081);
    server.addConnector(connector);

    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/");
    bb.setWar("src/main/webapp");

    server.setHandler(bb);

    try {
        System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
        server.start();
        System.in.read();
        System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
        server.stop();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:cc.wikitools.lucene.FindWikipediaArticleId.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(// w w  w. j a v a  2 s.co  m
            OptionBuilder.withArgName("path").hasArg().withDescription("index location").create(INDEX_OPTION));
    options.addOption(
            OptionBuilder.withArgName("string").hasArg().withDescription("article title").create(TITLE_OPTION));

    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (!cmdline.hasOption(TITLE_OPTION) || !cmdline.hasOption(INDEX_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(FindWikipediaArticleId.class.getName(), options);
        System.exit(-1);
    }

    File indexLocation = new File(cmdline.getOptionValue(INDEX_OPTION));
    if (!indexLocation.exists()) {
        System.err.println("Error: " + indexLocation + " does not exist!");
        System.exit(-1);
    }

    String title = cmdline.getOptionValue(TITLE_OPTION);

    PrintStream out = new PrintStream(System.out, true, "UTF-8");

    WikipediaSearcher searcher = new WikipediaSearcher(indexLocation);
    int id = searcher.getArticleId(title);

    out.println(title + ": id = " + id);

    searcher.close();
    out.close();
}