Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1.  
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileInputStream;
  5. import java.io.FileOutputStream;
  6. import java.io.FileReader;
  7. import java.io.FileWriter;
  8. import java.io.IOException;
  9. import java.io.PrintWriter; // или просто import java.io.*;
  10.  
  11. public class FileManager {
  12.  
  13. public void copyDataLine() throws IOException {
  14. try (BufferedReader in = new BufferedReader(new FileReader("res//first.txt"));
  15. PrintWriter out = new PrintWriter(new FileWriter("res//second.txt"))) {
  16. String str;
  17. while ((str = in.readLine()) != null) {
  18. out.println(str);
  19. }
  20.  
  21. }
  22. }
  23.  
  24. public void copyDataFileStream () throws IOException {
  25. try (FileReader in = new FileReader("res//first.txt");
  26. FileWriter out = new FileWriter("res//second.txt")) {
  27. int c;
  28. while ((c = in.read()) != -1 ) {
  29. out.write(c);
  30. }
  31.  
  32. }
  33. }
  34. public void copyData () throws IOException {
  35. FileInputStream in = null;
  36. FileOutputStream out = null;
  37.  
  38. try {
  39. in = new FileInputStream("res//first.txt");
  40. out = new FileOutputStream("res//second.txt");
  41. int c;
  42. while ((c = in.read()) != -1) {
  43. out.write(c);
  44. }
  45.  
  46.  
  47. } finally {
  48. if (in!=null) {
  49. in.close();
  50. }
  51. if (out != null) {
  52. out.close();
  53. }
  54. }
  55. }
  56. public static void main (String[] args) {
  57. FileManager fm = new FileManager();
  58. try {
  59. fm.copyDataLine();
  60. } catch (IOException e) {
  61. e.printStackTrace();
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement