Advertisement
Guest User

Untitled

a guest
Mar 26th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. package algorytmy;
  2. import java.io.BufferedReader;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6.  
  7. /**
  8. *
  9. * @author Długi
  10. */
  11. public class Algorytmy {
  12.  
  13. void czytaj(){
  14.  
  15. FileReader fr = null;
  16. String line = "";
  17.  
  18. try{
  19. fr = new FileReader("123.txt");
  20. }catch (FileNotFoundException e){
  21. System.out.println("Error, could not open a file");
  22. System.exit(1);
  23. }
  24.  
  25. BufferedReader bfr = new BufferedReader(fr);
  26. // reading lines from file
  27. try {
  28. while((line = bfr.readLine()) != null){
  29. System.out.println(line);
  30. }
  31. } catch (IOException e) {
  32. System.out.println("Error, could not open a file");
  33. System.exit(2);
  34. }
  35.  
  36. // closing a file
  37. try {
  38. fr.close();
  39. } catch (IOException e) {
  40. System.out.println("Error, could not close a file");
  41. System.exit(3);
  42. }
  43. }
  44.  
  45.  
  46. public static void main(String[] args) {
  47.  
  48.  
  49.  
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement