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

public static void main(String[] args) throws IOException {
    String fileName = "randomaccessfile.txt";
    File fileObject = new File(fileName);

    if (!fileObject.exists()) {
        initialWrite(fileName);//from w ww  .j ava2 s  . co m
    }
    readFile(fileName);
    readFile(fileName);
}

From source file:Main.java

public static void main(String[] args) {
    File file = new File("config.xml");

    int errCode = 0;
    if (!file.exists()) {
        errCode = 1;//from www  . java  2  s .c om
    } else {
        errCode = 0;
    }

    // When the error code is not zero go terminate
    if (errCode > 0) {
        System.exit(errCode);
    }
}

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  ww w  . jav a  2s  .  com
    }
    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:de.rwhq.btree.run.PrintTree.java

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

    final File f = new File("/tmp/indexha");
    if (!f.exists())
        throw new IllegalArgumentException("File does not exist");

    final ResourceManager resourceManager = new ResourceManagerBuilder().file(f).build();
    final BTree<Integer, String> tree = BTree.create(resourceManager, IntegerSerializer.INSTANCE,
            FixedStringSerializer.INSTANCE_1000, IntegerComparator.INSTANCE);

    final Iterator<String> it = tree.getIterator();
    while (it.hasNext()) {
        System.out.println(it.next());
    }//from   w w  w . j  av a 2 s  .c  om
}

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.exists());
}

From source file:Empty.java

public static void main(String[] argv) {
    if (argv.length != 1) { // no progname in argv[0]
        System.err.println("usage: Empty dirname");
        System.exit(1);/*www .ja  va2  s . c om*/
    }

    File dir = new File(argv[0]);
    if (!dir.exists()) {
        System.out.println(argv[0] + " does not exist");
        return;
    }

    String[] info = dir.list();
    for (int i = 0; i < info.length; i++) {
        File n = new File(argv[0] + dir.separator + info[i]);
        if (!n.isFile()) // skip ., .., other directories too
            continue;
        System.out.println("removing " + n.getPath());
        if (!n.delete())
            System.err.println("Couldn't remove " + n.getPath());
    }
}

From source file:KillFilesByName.java

public static void main(String[] argv) {
    if (argv.length != 2) {
        System.err.println("usage: KillFilesByName dirname pattern");
        System.exit(1);//from  w w  w .  j  a  va 2s .  c  o m
    }

    File dir = new File(argv[0]);
    if (!dir.exists()) {
        System.out.println(argv[0] + " does not exist");
        return;
    }
    String patt = argv[1];

    String[] info = dir.list();
    for (int i = 0; i < info.length; i++) {
        File n = new File(argv[0] + dir.separator + info[i]);
        if (!n.isFile()) { // skip ., .., other directories, etc.
            continue;
        }
        if (info[i].indexOf(patt) == -1) { // name doesn't match
            continue;
        }
        System.out.println("removing " + n.getPath());
        if (!n.delete())
            System.err.println("Couldn't remove " + n.getPath());
    }
}

From source file:fi.jasoft.plugin.LibSassCompiler.java

public static void main(String[] args) throws Exception {
    File inputFile = new File(args[0]);
    File outputFile = new File(args[1]);
    if (!outputFile.exists()) {
        outputFile.createNewFile();/*w w  w  .  j av  a2s.  c  o m*/
    }

    File sourceMapFile = new File(args[1] + ".map");
    if (!sourceMapFile.exists()) {
        sourceMapFile.createNewFile();
    }

    File unpackedThemes = new File(args[2]);
    File unpackedInputFile = Paths
            .get(unpackedThemes.getCanonicalPath(), inputFile.getParentFile().getName(), inputFile.getName())
            .toFile();

    Compiler compiler = new Compiler();
    Options options = new Options();

    try {
        Output output = compiler.compileFile(unpackedInputFile.toURI(), outputFile.toURI(), options);
        FileUtils.write(outputFile, output.getCss(), StandardCharsets.UTF_8.name());
        FileUtils.write(sourceMapFile, output.getSourceMap(), StandardCharsets.UTF_8.name());
    } catch (CompilationException e) {
        outputFile.delete();
        sourceMapFile.delete();
        throw e;
    }
}

From source file:Attr.java

public static void main(String args[]) {
    File path = new File(args[0]); // grab command-line argument
    String exists = getYesNo(path.exists());
    String canRead = getYesNo(path.canRead());
    String canWrite = getYesNo(path.canWrite());
    String isFile = getYesNo(path.isFile());
    String isHid = getYesNo(path.isHidden());
    String isDir = getYesNo(path.isDirectory());
    String isAbs = getYesNo(path.isAbsolute());
    System.out.println("File attributes for '" + args[0] + "'");
    System.out.println("Exists    : " + exists);
    if (path.exists()) {
        System.out.println("Readable   : " + canRead);
        System.out.println("Writable   : " + canWrite);
        System.out.println("Is directory : " + isDir);
        System.out.println("Is file    : " + isFile);
        System.out.println("Is hidden   : " + isHid);
        System.out.println("Absolute path : " + isAbs);
    }/*from   w ww.  ja  va 2s  . c om*/
}

From source file:dk.qabi.imapfs.IMAPMount.java

public static void main(String[] args) throws MessagingException, MalformedURLException {

    if (args.length < 2) {
        System.out.println("[Error]: Must specify a mounting point");
        System.out.println();/*from w  w  w. j a  v  a 2  s  .  co m*/
        System.out.println("[Usage]: imapfsmnt <mounting point>");
        System.exit(-1);
    }

    final String urlSpec = args[0];
    final URL url = new URL(null, urlSpec, new IMAPStreamHandler());
    final String mountpoint = args[1];

    String[] fs_args = new String[4];
    fs_args[0] = "-f";
    fs_args[1] = "-s";
    fs_args[2] = mountpoint;
    fs_args[3] = "-ovolname=" + url.getHost() + ",fssubtype=7";

    Filesystem imapfs = new LoggingFilesystem(new IMAPFileSystem(url), LogFactory.getLog("dk.qabi.imapfs"));

    File m = new File(mountpoint);
    if (!m.exists())
        m.mkdirs();

    try {
        FuseMount.mount(fs_args, imapfs);
    } catch (Exception e) {
        e.printStackTrace();
    }

}