importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.IOException;publicclass BinaryStreamsV2 {// The two constants below specify the input and output jpg files. // Change the path and filenames to match jpeg files on your computer. private static final String ORIGINAL_FILENAME = "C:\\example.jpg"; private static final String COPY_FILENAME = "C:\\anewexample.jpg"; public static void main(String[] args) throws IOException { //The new try with resources feature of Java 7 means handling resources is //much easier. All you need to do is initialize them at the start of the try block and it will //handle their closure. try ( FileInputStream fileInput = new FileInputStream(ORIGINAL_FILENAME); FileOutputStream fileOutput = new FileOutputStream(COPY_FILENAME)){ int data; //For each byte read it in from the input file //and write it to the output file //When the end of the file is reached a //value of -1 is returned. while ((data = fileInput.read()) != -1) { fileOutput.write(data); } } catch (IOException e) //Catch the IO error and print out the message { System.out.println("Error message: " + e.getMessage()); } } }
Main.java:1: error: reached end of file while parsing
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class BinaryStreamsV2 { // The two constants below specify the input and output jpg files. // Change the path and filenames to match jpeg files on your computer. private static final String ORIGINAL_FILENAME = "C:\\example.jpg"; private static final String COPY_FILENAME = "C:\\anewexample.jpg"; public static void main(String[] args) throws IOException { //The new try with resources feature of Java 7 means handling resources is //much easier. All you need to do is initialize them at the start of the try block and it will //handle their closure. try ( FileInputStream fileInput = new FileInputStream(ORIGINAL_FILENAME); FileOutputStream fileOutput = new FileOutputStream(COPY_FILENAME)){ int data; //For each byte read it in from the input file //and write it to the output file //When the end of the file is reached a //value of -1 is returned. while ((data = fileInput.read()) != -1) { fileOutput.write(data); } } catch (IOException e) //Catch the IO error and print out the message { System.out.println("Error message: " + e.getMessage()); } } }
^
1 error