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() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Main.java

public static void main(String[] args) {
    OutputStream fileOutputStream;
    try {/*from  ww w.ja  va 2  s.  c  om*/
        fileOutputStream = new FileOutputStream("c:/a.txy");
        Runtime runTime = Runtime.getRuntime();
        runTime.getLocalizedOutputStream(fileOutputStream);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    InputStream fileInputStream;// w w  w. j a  v  a  2 s  .c  o m
    try {
        fileInputStream = new FileInputStream("c:/a.txy");
        Runtime runTime = Runtime.getRuntime();
        runTime.getLocalizedInputStream(fileInputStream);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    String destFile = "luci3.txt";

    try (PrintStream ps = new PrintStream(destFile)) {
        ps.println("test");
        ps.println("test1");
        ps.println("test2");
        ps.print("test3");

        // flush the print stream
        ps.flush();// w  ww  .  j a v a 2  s  .  co m

        System.out.println("Text has  been  written to " + (new File(destFile).getAbsolutePath()));
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    File file = new File("xyz.txt");
    Formatter fm = null;//from w  w  w.  j  a  v a  2s .  c  o  m
    try {
        // Create a Formatter that will write the output the file
        fm = new Formatter(file);

        // Formatting strings
        fm.format("%1$s, %2$s,  and  %3$s %n", "A", "B", "C");
        fm.format("%3$s, %2$s,  and  %1$s %n", "A", "B", "C");

        // Format more text here...
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } finally {
        if (fm != null) {
            fm.close();
        }
    }
}

From source file:MainClass.java

public static void main(String[] args) {

    try {/*from   ww w.  ja v  a  2s  .c o  m*/
        String FILE = "c:\\systemin.txt";
        FileOutputStream outStr = new FileOutputStream(FILE, true);
        PrintStream printStream = new PrintStream(outStr);

        System.setErr(printStream);

        Timestamp now = new Timestamp(System.currentTimeMillis());
        System.out.println(now.toString() + ": This is text that should go to the file");

        outStr.close();
        printStream.close();
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
        System.exit(-1);
    } catch (IOException ex) {
        ex.printStackTrace();
        System.exit(-1);
    }
}

From source file:com.project.finalproject.Send.java

public static void main(String[] argv) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();
    channel.queueDeclare(QUEUE_NAME, false, false, false, null);

    try {//from ww w . jav  a2s.co  m
        InputStream is = new FileInputStream("hr.json");
        String jsontxt = IOUtils.toString(is);
        JSONObject jsonObject = new JSONObject(jsontxt);
        JSONArray stream = jsonObject.getJSONArray("stream");
        for (int i = 0; i < stream.length(); i++) {
            String message = stream.getJSONObject(i).getString("value");
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
            System.out.println(" [x] Sent '" + message + "'");
            TimeUnit.SECONDS.sleep(1);
        }
    } catch (FileNotFoundException fe) {
        fe.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    channel.close();
    connection.close();
}

From source file:Main.java

License:asdf

public static void main(String[] args) {
    String dataSourceFile = "asdf.txt";
    try (FileInputStream fin = new FileInputStream(dataSourceFile)) {

        byte byteData;
        while ((byteData = (byte) fin.read()) != -1) {
            System.out.print((char) byteData);
        }// w  w  w. j a v a 2 s  .co m
    } catch (FileNotFoundException e) {
        ;
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.bright.utils.ZipFile.java

public static void main(String[] args) {

    try {/* w w  w  .  jav  a  2s . co  m*/
        // name of zip file to create
        String outFilename = args[1];

        // create ZipOutputStream object
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));

        // path to the folder to be zipped
        File zipFolder = new File(args[0]);

        int len = zipFolder.getAbsolutePath().lastIndexOf(File.separator);
        String baseName = zipFolder.getAbsolutePath().substring(0, len + 1);

        addFolderToZip(zipFolder, out, baseName);
        System.out.println("Created ZIP file: " + args[1]);

        out.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.jeffy.hdfs.HDFSWriteFile.java

/**
 * ??hdfs//from  www  .  ja va 2  s.  co m
 * 
 * @param args
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.err.println("Please input two parameter!");
        System.out.println("Parameter: localfile hdfsfile");
        System.exit(1);
    }

    String localPath = args[0];
    String hdfsPath = args[1];
    //??
    Configuration config = new Configuration();
    //??
    try (InputStream in = new BufferedInputStream(new FileInputStream(localPath))) {
        FileSystem fs = FileSystem.get(URI.create(hdfsPath), config);
        try (FSDataOutputStream out = fs.create(new Path(hdfsPath), new Progressable() {
            @Override
            public void progress() {
                System.out.println(".");
            }
        })) {
            //??OutputStream,Hadooporg.apache.commons.io.IOUtils
            IOUtils.copy(in, out);
            System.out.println("File copy finished.");
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:PrintServiceTest.java

public static void main(String[] args) {
    DocFlavor flavor = DocFlavor.URL.GIF;
    PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null);
    if (args.length == 0) {
        if (services.length == 0)
            System.out.println("No printer for flavor " + flavor);
        else {//from   w  ww .j av  a  2s. c  om
            System.out.println("Specify a file of flavor " + flavor
                    + "\nand optionally the number of the desired printer.");
            for (int i = 0; i < services.length; i++)
                System.out.println((i + 1) + ": " + services[i].getName());
        }
        System.exit(0);
    }
    String fileName = args[0];
    int p = 1;
    if (args.length > 1)
        p = Integer.parseInt(args[1]);
    try {
        if (fileName == null)
            return;
        FileInputStream in = new FileInputStream(fileName);
        Doc doc = new SimpleDoc(in, flavor, null);
        DocPrintJob job = services[p - 1].createPrintJob();
        job.print(doc, null);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (PrintException e) {
        e.printStackTrace();
    }
}