Skip to content

Instantly share code, notes, and snippets.

@Kurt-P
Created August 31, 2013 02:37
Show Gist options
  • Save Kurt-P/6395903 to your computer and use it in GitHub Desktop.
Save Kurt-P/6395903 to your computer and use it in GitHub Desktop.
Open an existing input file and copy it to non-existing output file.
public class jcopy {
public static void main(String[] args) throws IOException {
BufferedReader stdin = new BufferedReader( new InputStreamReader(System.in));
System.out.println("enter Input File Name: ");
String InputFile = stdin.readLine();
File infile = new File(InputFile);
InputStream fin = new FileInputStream(infile);
System.out.println("enter Outut File Name: ");
String OutputFile = stdin.readLine();
File outfile = new File(OutputFile);
OutputStream fout = new FileOutputStream(outfile);
int len;
byte[] buf = new byte[1024];
while ((len = fin.read(buf)) > 0) {
fout.write(buf, 0, len);
}
fin.close();
fout.close();
System.out.println("copied " + InputFile + " to " + OutputFile);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment