Example usage for java.io FileNotFoundException printStackTrace

List of usage examples for java.io FileNotFoundException printStackTrace

Introduction

In this page you can find the example usage for java.io FileNotFoundException printStackTrace.

Prototype

public void printStackTrace(PrintStream s) 

Source Link

Document

Prints this throwable and its backtrace to the specified print stream.

Usage

From source file:Main.java

public static void main(String[] a) {
    FileInputStream inputFile = null;
    try {//w  w w .  java  2  s .co m
        inputFile = new FileInputStream("C:/myFile.txt");
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
    }
}

From source file:MainClass.java

public static void main(String[] a) {
    FileOutputStream outputFile = null; // Place to store the stream reference
    try {//  w  w  w. j a v a  2 s  .co  m
        outputFile = new FileOutputStream("myFile.txt");
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
    }
}

From source file:MainClass.java

public static void main(String[] a) {
    File aFile = new File("C:/myFile.txt");
    FileInputStream inputFile = null;
    try {//from   w  ww. j  a va2 s .co  m
        inputFile = new FileInputStream(aFile);
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
        System.exit(1);
    }
}

From source file:MainClass.java

public static void main(String[] a) {
    File aFile = new File("charData.txt");
    FileInputStream inFile = null;
    try {/*from   w  w w . ja v  a 2s.  c o m*/
        inFile = new FileInputStream(aFile);
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
        System.exit(1);
    }
    FileChannel inChannel = inFile.getChannel();
}

From source file:MainClass.java

public static void main(String[] a) {
    File aFile = new File("C:/myFile.text");
    FileOutputStream outputFile = null; // Place to store an output stream
                                        // reference
    try {/*from ww  w .  java  2 s  . c  om*/
        // Create the stream opened to write
        outputFile = new FileOutputStream(aFile);
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
        System.exit(1);
    }
    // Get the channel for the file
    FileChannel outputChannel = outputFile.getChannel();
}

From source file:MainClass.java

public static void main(String[] Args) {
    String filepath = "C:/myFile.txt";
    File aFile = new File(filepath);
    FileOutputStream outputFile = null;
    if (aFile.isFile()) {
        File newFile = aFile;//from ww w  .j  av  a  2 s.  co  m
        do {
            String name = newFile.getName();
            int period = name.indexOf('.');
            newFile = new File(newFile.getParent(),
                    name.substring(0, period) + "_old" + name.substring(period));
        } while (newFile.exists());
        aFile.renameTo(newFile);
    }
    try {
        outputFile = new FileOutputStream(aFile);
        System.out.println("myFile.txt output stream created");
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
    }
}

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   w  ww  . ja v  a  2 s .c o m*/
    }
    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:MainClass.java

public static void main(String[] args) {
    String phrase = new String("text\n");
    String dirname = "C:/test"; // Directory name
    String filename = "byteData.txt";
    File aFile = new File(dirname, filename);
    // Create the file output stream
    FileOutputStream file = null;
    try {/*from w w  w. j  a  v a2s. c  o  m*/
        file = new FileOutputStream(aFile, true);
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
    }
    FileChannel outChannel = file.getChannel();
    ByteBuffer buf = ByteBuffer.allocate(phrase.length());
    byte[] bytes = phrase.getBytes();
    buf.put(bytes);
    buf.flip();
    try {
        outChannel.write(buf);
        file.close();
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    File aFile = new File("C:/test.bin");
    FileInputStream inFile = null;
    try {/*  ww w .ja  v a2s .c  om*/
        inFile = new FileInputStream(aFile);
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
    }
    FileChannel inChannel = inFile.getChannel();
    final int PRIMECOUNT = 6;
    ByteBuffer buf = ByteBuffer.allocate(8 * PRIMECOUNT);
    long[] primes = new long[PRIMECOUNT];
    try {
        while (inChannel.read(buf) != -1) {
            ((ByteBuffer) (buf.flip())).asLongBuffer().get(primes);
            for (long prime : primes) {
                System.out.printf("%10d", prime);
            }
            buf.clear();
        }
        inFile.close();
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    File aFile = new File("afile.txt");
    FileOutputStream outputFile = null;
    try {//from w  w w . ja v a  2  s  .c om
        outputFile = new FileOutputStream(aFile, true);
        System.out.println("File stream created successfully.");
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
    }
    ByteBuffer buf = ByteBuffer.allocate(1024);
    System.out.println("\nByte buffer:");
    System.out.printf("position = %2d  Limit = %4d  capacity = %4d%n", buf.position(), buf.limit(),
            buf.capacity());

    // Create a view buffer
    CharBuffer charBuf = buf.asCharBuffer();
    System.out.println("Char view buffer:");
    System.out.printf("position = %2d  Limit = %4d  capacity = %4d%n", charBuf.position(), charBuf.limit(),
            charBuf.capacity());
    try {
        outputFile.close(); // Close the O/P stream & the channel
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
}