Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package środa2;
- import java.io.FileWriter;
- import java.io.FileReader;
- import java.io.PrintWriter;
- import java.io.BufferedReader;
- import java.io.IOException;
- public class txt {
- static void zapisz(String s){
- try{
- FileWriter fw = new FileWriter("moj.txt", true);
- fw.write(s);
- fw.close();
- }catch(IOException e){
- System.out.println("Błąd wyjścia");
- }
- }
- static void zapisz_wiersz(String s){
- try{
- PrintWriter pw = new PrintWriter(new FileWriter("moj.txt", true));
- pw.println(s);
- pw.close();
- }catch(IOException e){
- System.out.println("Błąd wyjścia");
- }
- }
- static void odczyt(){
- try{
- FileReader fr = new FileReader("moj.txt");
- int i;
- do{
- i = fr.read();
- System.out.print((char)i);
- }while(i != -1);
- fr.close();
- }catch(IOException e){
- System.out.println("Błąd wejścia");
- }
- }
- static void odczyt_wierszy(){
- try{
- BufferedReader br = new BufferedReader(new FileReader("moj.txt"));
- String s;
- do{
- s = br.readLine();
- System.out.println(s);
- }
- while(s != null);
- br.close();
- }catch(IOException e){
- System.out.println("Błąd wejścia");
- }
- }
- public static void main(String[] args) {
- //zapisz("Idzie zima \n");
- //zapisz_wiersz("Idzie zima");
- //odczyt();
- odczyt_wierszy();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement