Skip to content

Instantly share code, notes, and snippets.

@golenishchev
Created January 5, 2016 17:38
Show Gist options
  • Save golenishchev/17a9e9f57a0250aafea8 to your computer and use it in GitHub Desktop.
Save golenishchev/17a9e9f57a0250aafea8 to your computer and use it in GitHub Desktop.
Lesson14v2
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;
public class FileManager{
public static void copyFile(String firstFile, String secondFile) throws Exception {
try (
BufferedReader br = new BufferedReader(new FileReader(firstFile));
PrintWriter pw = new PrintWriter(new FileWriter(secondFile));
) {
int line;
while ((line = br.read()) != -1) {
pw.write(line);
}
}
System.out.println("All done");
}
public static void main(String[] args) throws Exception {
String firstFile = "first.txt";
String secondFile = "second3.txt";
copyFile(firstFile,secondFile);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment