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:de.unisb.cs.st.javalanche.mutation.util.FilePerformanceTest.java

public static void main(String[] args) throws IOException {
    int limit = 1000;
    int total = 0;
    StopWatch stp = new StopWatch();
    stp.start();//ww w.  ja  va  2 s  . c om
    File dir = new File("mutation-files/tmp");
    dir.mkdir();
    for (int i = 0; i < limit; i++) {
        Map<String, Set<Integer>> map = getMap();
        File tempFile = new File(dir, "test-" + i + ".ser");
        if (!tempFile.exists()) {
            SerializeIo.serializeToFile(map, tempFile);
        } else {
            Map<String, Set<Integer>> deserialize = SerializeIo.get(tempFile);
            total += deserialize.size();
        }
    }
    System.out.println(
            "Handling " + limit + " files took " + DurationFormatUtils.formatDurationHMS(stp.getTime()));
}

From source file:com.ok2c.lightmtp.examples.SendMailExample.java

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

    if (args.length < 3) {
        System.out.println("Usage: sender recipient1[;recipient2;recipient3;...] file");
        System.exit(0);//from   w  w  w.  ja v  a2s . c om
    }

    String sender = args[0];
    List<String> recipients = new ArrayList<String>();
    StringTokenizer tokenizer = new StringTokenizer(args[1], ";");
    while (tokenizer.hasMoreTokens()) {
        String s = tokenizer.nextToken();
        s = s.trim();
        if (s.length() > 0) {
            recipients.add(s);
        }
    }

    File src = new File(args[2]);
    if (!src.exists()) {
        System.out.println("File '" + src + "' does not exist");
        System.exit(0);
    }

    DeliveryRequest request = new BasicDeliveryRequest(sender, recipients, new FileSource(src));

    MailUserAgent mua = new DefaultMailUserAgent(TransportType.SMTP, IOReactorConfig.DEFAULT);
    mua.start();

    try {

        InetSocketAddress address = new InetSocketAddress("localhost", 2525);

        Future<DeliveryResult> future = mua.deliver(new SessionEndpoint(address), 0, request, null);

        DeliveryResult result = future.get();
        System.out.println("Delivery result: " + result);

    } finally {
        mua.shutdown();
    }
}

From source file:demo.wssec.client.Client.java

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

    if (args.length == 0) {
        System.out.println("please specify wsdl");
        System.exit(1);// w  ww  . j a v a2s .  c o  m
    }

    URL wsdlURL;
    File wsdlFile = new File(args[0]);
    if (wsdlFile.exists()) {
        wsdlURL = wsdlFile.toURI().toURL();
    } else {
        wsdlURL = new URL(args[0]);
    }

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = new ClassPathResource("wssec-client.xml").getURL();

    Bus bus = bf.createBus(busFile.toString());
    SpringBusFactory.setDefaultBus(bus);
    SpringBusFactory.setThreadDefaultBus(bus);

    Service service = Service.create(wsdlURL, SERVICE_NAME);
    Greeter port = service.getPort(PORT_NAME, Greeter.class);

    System.out.println("Invoking greetMe...");
    try {
        String resp = port.greetMe(System.getProperty("user.name"));
        System.out.println("Server responded with: " + resp);
        System.out.println();

    } catch (Exception e) {
        System.out.println("Invocation failed with the following: " + e.getCause());
        System.out.println();
    }

    System.exit(0);
}

From source file:com.dopsun.msg4j.tools.CodeGen.java

/**
 * @param args// w w w  .j  av a 2 s .c o m
 * @throws IOException
 * @throws MalformedURLException
 * @throws ParseException
 */
public static void main(String[] args) throws MalformedURLException, IOException, ParseException {
    Options options = new Options();
    options.addOption("o", "out", true, "Output file");
    options.addOption("s", "src", true, "Source file");
    options.addOption("l", "lang", true, "Language");

    CommandLineParser cmdParser = new DefaultParser();
    CommandLine cmd = cmdParser.parse(options, args);

    String lang = cmd.getOptionValue("lang", "Java");
    String srcFile = cmd.getOptionValue("src");
    String outFile = cmd.getOptionValue("out");

    YamlModelSource modelSource = YamlModelSource.load(new File(srcFile).toURI().toURL());
    YamlModelParser parser = YamlModelParser.create();
    ModelInfo modelInfo = parser.parse(modelSource);

    String codeText = null;
    if (lang.equals("Java")) {
        codeText = Generator.JAVA.generate(modelInfo);
    } else {
        throw new UnsupportedOperationException("Unrecognized lang: " + lang);
    }

    if (outFile != null) {
        File file = new File(outFile);
        if (file.exists()) {
            file.delete();
        }
        file.createNewFile();

        Files.append(codeText, new File(outFile), Charsets.UTF_8);
    } else {
        System.out.println(codeText);
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    File originFile = new File("c:\\file1.txt");
    File destinationFile = new File("c:\\file1.txt");
    if (!originFile.exists() || destinationFile.exists()) {
        return;/*ww  w. j av a2s  .co  m*/
    }
    try {
        byte[] readData = new byte[1024];
        FileInputStream fis = new FileInputStream(originFile);
        FileOutputStream fos = new FileOutputStream(destinationFile);
        int i = fis.read(readData);

        while (i != -1) {
            fos.write(readData, 0, i);
            i = fis.read(readData);
        }
        fis.close();
        fos.close();
    } catch (IOException e) {
        System.out.println(e);
    }
}

From source file:Delete.java

public static void main(String[] args) {
    String fileName = "file.txt";
    // A File object to represent the filename
    File f = new File(fileName);

    // Make sure the file or directory exists and isn't write protected
    if (!f.exists())
        throw new IllegalArgumentException("Delete: no such file or directory: " + fileName);

    if (!f.canWrite())
        throw new IllegalArgumentException("Delete: write protected: " + fileName);

    // If it is a directory, make sure it is empty
    if (f.isDirectory()) {
        String[] files = f.list();
        if (files.length > 0)
            throw new IllegalArgumentException("Delete: directory not empty: " + fileName);
    }//from w  w w  . j  a v  a  2 s .c  om

    // Attempt to delete it
    boolean success = f.delete();

    if (!success)
        throw new IllegalArgumentException("Delete: deletion failed");
}

From source file:Main.java

public static void main(String[] args) {
    boolean areFilesIdentical = true;
    File file1 = new File("c:\\file1.txt");
    File file2 = new File("c:\\file2.txt");
    if (!file1.exists() || !file2.exists()) {
        System.out.println("One or both files do not exist");
        System.out.println(false);
    }/*  ww  w  .  j  av a2  s .  c  om*/
    System.out.println("length:" + file1.length());
    if (file1.length() != file2.length()) {
        System.out.println("lengths not equal");
        System.out.println(false);
    }
    try {
        FileInputStream fis1 = new FileInputStream(file1);
        FileInputStream fis2 = new FileInputStream(file2);
        int i1 = fis1.read();
        int i2 = fis2.read();
        while (i1 != -1) {
            if (i1 != i2) {
                areFilesIdentical = false;
                break;
            }
            i1 = fis1.read();
            i2 = fis2.read();
        }
        fis1.close();
        fis2.close();
    } catch (IOException e) {
        System.out.println("IO exception");
        areFilesIdentical = false;
    }
    System.out.println(areFilesIdentical);
}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step4BoilerPlateRemoval.java

public static void main(String[] args) throws IOException {
    // input dir - list of xml query containers
    // step3-filled-raw-html
    File inputDir = new File(args[0]);

    // output dir
    File outputDir = new File(args[1]);
    if (!outputDir.exists()) {
        outputDir.mkdirs();/*from  ww  w  .  j a v a2 s.  c o m*/
    }

    // keep original html? (true == default)
    boolean keepOriginalHTML = !(args.length > 2 && "false".equals(args[2]));

    System.out.println(keepOriginalHTML);

    BoilerPlateRemoval boilerPlateRemoval = new JusTextBoilerplateRemoval();

    // iterate over query containers
    for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) {
        QueryResultContainer queryResultContainer = QueryResultContainer
                .fromXML(FileUtils.readFileToString(f, "utf-8"));

        for (QueryResultContainer.SingleRankedResult rankedResults : queryResultContainer.rankedResults) {
            // boilerplate removal

            // there are some empty (corrupted) documents in ClueWeb, namely 0308wb-83.warc.gz
            if (rankedResults.originalHtml != null) {

                rankedResults.plainText = boilerPlateRemoval.getMinimalHtml(rankedResults.originalHtml, null);
            }

            if (!keepOriginalHTML) {
                rankedResults.originalHtml = null;
            }
        }

        // and save the query to output dir
        File outputFile = new File(outputDir, queryResultContainer.qID + ".xml");
        FileUtils.writeStringToFile(outputFile, queryResultContainer.toXML(), "utf-8");
        System.out.println("Finished " + outputFile);
    }

}

From source file:com.trackplus.ddl.DataReaderTest.java

public static void main(String[] args) {
    DatabaseInfo databaseInfo = createFirebirdDbInfo();
    Logger LOGGER = LogManager.getLogger(DataReader.class);
    LoggingConfigBL.setLevel(LOGGER, Level.DEBUG);

    String dbaseDir = "d:\\svn2015\\core\\com.trackplus.core\\src\\main\\webapp\\dbase";
    String tmpDir = "d:\\tmp7\\7";
    File file = new File(tmpDir);
    if (!file.exists()) {
        file.mkdirs();/*from   w  w w . j  av a2 s  . com*/
    }
    exportSchema(new File(tmpDir), dbaseDir);

    try {
        DataReader.writeDataToSql(databaseInfo, tmpDir);
    } catch (DDLException e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
    }
}

From source file:Main.java

public static void main(String[] args) {
    boolean areFilesIdentical = true;
    File file1 = new File("c:\\file1.txt");
    File file2 = new File("c:\\file2.txt");

    if (!file1.exists() || !file2.exists()) {
        System.out.println("One or both files do not exist");
        System.out.println(false);
    }//from w w w . j  a  v  a  2s . c o m

    System.out.println("length:" + file1.length());
    if (file1.length() != file2.length()) {
        System.out.println("lengths not equal");
        System.out.println(false);
    }

    try {
        FileInputStream fis1 = new FileInputStream(file1);
        FileInputStream fis2 = new FileInputStream(file2);
        int i1 = fis1.read();
        int i2 = fis2.read();
        while (i1 != -1) {
            if (i1 != i2) {
                areFilesIdentical = false;
                break;
            }
            i1 = fis1.read();
            i2 = fis2.read();
        }
        fis1.close();
        fis2.close();
    } catch (IOException e) {
        System.out.println("IO exception");
        areFilesIdentical = false;
    }
    System.out.println(areFilesIdentical);
}