Skip to content

Instantly share code, notes, and snippets.

@DeepSky8
Created September 2, 2015 00:13
Show Gist options
  • Select an option

  • Save DeepSky8/d9ab054c5cfc2d084d8e to your computer and use it in GitHub Desktop.

Select an option

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?
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