Guest User

Untitled

a guest
Mar 14th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. /**
  4.  * Created by Maciek on 2016-03-14.
  5.  */
  6. public class FileReader {
  7.     private FileOutputStream fout;
  8.     private FileInputStream fin;
  9.     private String x;
  10.     private TextEditor textEditor = new TextEditor();
  11.     public String y = "";
  12.  
  13.  
  14.     public void saveFile(String txt) {
  15.         try {
  16.             fout = new FileOutputStream("test.txt");
  17.         } catch (IOException e) {
  18.             System.out.println("Blad wejscia-wyjscia");
  19.             System.exit(-1);
  20.         }
  21.         DataOutputStream out = new DataOutputStream(fout);
  22.         try {
  23.             out.writeBytes(txt);
  24.         } catch (IOException i) {
  25.             System.out.println("Probujesz zapisac pusty plik.");
  26.         }
  27.     }
  28.  
  29.     public void readFile() {
  30.         try {
  31.             fin = new FileInputStream("test.txt");
  32.             BufferedReader brin = new BufferedReader(new InputStreamReader(fin));
  33.             while ((x = brin.readLine()) != null) {
  34.                 System.out.println(x);
  35.                 y += x +"\n";
  36.             }
  37.         } catch (IOException e) {
  38.             System.out.println("-1");
  39.             System.exit(-1);
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment