java - I/O Not Working (Copy File, Paste It) -
I'm trying to get this piece of code to work. This is a basic I / O system that copies a file and pastes it in the same directory with the chosen name. It should be simple, but for some reason the program runs, it creates another file, but then it gets trapped. The CPU sits at about 5% for the Java process and the file is never full. It only copies some figures and then I think it has got stuck in an infinite loop somewhere.
I have already compared my code with the byte stream tutorial.
Extra: I just read it what he was reading and reading this value I can tell it what it is. Can anyone tell me what I am doing wrong? Thank you (PS: I am using Eclipse 4.2.0.). This is the file I am copying: I run this main section of my program: Try turn off the output stream. 255 is stuck on the infinite loop. If it helps, besides, I compile the code directly from the Oracle website and it does the same thing.
package fileio; Import java.io * *; Import system Debug; Public class file usage {public static zero copyFileTo (string file2Copy, string file2Paste) {FileInputStream fin = null; FileOutputStream fout = null; Try {fin = new FileInputStream (file2Copy); Fout = new FileOutputStream (file2Paste); Int aByte; While ((abyte = fin.read ())! = -1) {fout.write (aByte); }} Hold (FileNotFoundException e) {Debug.out ("Error: File not found:" + file2Copy); } Grip (IOException e) {Debug.out ("Error: File IO Exception Copy:" + file2Copy); } Hold (exception e) {Debug.out ("Error: Normal Exception Closing Stream:" + file2Copy); } Finally {try {fin.close ()} fout.close (); } Catch (IOException e) {Debug.out ("Error: File IO exceptions closing currents:" + file2Copy); } Hold (exception e) {Debug.out ("Error: Normal Exception Closing Stream:" + file2Copy); }}}}
fileUtil.copyFileTo ("google.bmp", "google (1 ) Bmp "); Before
fout.flush () to
Comments
Post a Comment