Created
September 2, 2015 00:13
-
-
Save DeepSky8/d9ab054c5cfc2d084d8e to your computer and use it in GitHub Desktop.
On line 22, the "int len;" is declared on line 22, and then initialized with a value on line 23, correct?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.lynda.files; | |
| import java.io.File; | |
| import java.io.FileInputStream; | |
| import java.io.FileNotFoundException; | |
| import java.io.FileOutputStream; | |
| import java.io.IOException; | |
| import java.io.InputStream; | |
| import java.io.OutputStream; | |
| public class CopyFile { | |
| public static void main(String[] args) { | |
| try { | |
| File f1 = new File("loremipsum.txt"); | |
| File f2 = new File("target.txt"); | |
| InputStream in = new FileInputStream(f1); | |
| OutputStream out = new FileOutputStream(f2); | |
| byte[] buf = new byte[1024]; | |
| int len; | |
| while ((len = in.read(buf)) > 0) { | |
| out.write(buf, 0, len); | |
| } | |
| in.close(); | |
| out.close(); | |
| System.out.println("File Copied"); | |
| } catch (FileNotFoundException e) { | |
| // TODO Auto-generated catch block | |
| e.printStackTrace(); | |
| } catch (IOException e) { | |
| // TODO Auto-generated catch block | |
| e.printStackTrace(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment