Guest User

Untitled

a guest
Feb 23rd, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4. import java.util.Scanner;
  5. import java.io.FileNotFoundException;
  6. import java.lang.String;
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. public class FractionDemo extends Fraction {
  14. public static void main(String[] args) {
  15.  
  16.  
  17.  
  18. StringBuilder sb = new StringBuilder();
  19. BufferedReader br = null;
  20. Scanner fileInput = new Scanner(System.in);
  21. System.out.println("Please make sure your text file is in your src folder and\n"
  22. +"enter your file name\n" + "Example:Lab1_InputFile.txt");
  23. String nameOfFile = fileInput.next();
  24.  
  25.  
  26. try {
  27. br = new BufferedReader(new FileReader("src/" + nameOfFile));
  28. String line;
  29. while ((line = br.readLine()) != null) {
  30. if (sb.length() > 0) {
  31. sb.append("\n");
  32. }
  33. sb.append(line);
  34. }
  35. } catch (IOException e) {
  36. e.printStackTrace();
  37. } finally {
  38. try {
  39. if (br != null) {
  40. br.close();
  41. }
  42. } catch (IOException ex) {
  43. ex.printStackTrace();
  44. }
  45. }
  46. String contents = sb.toString();
  47. System.out.println(contents);
  48.  
  49.  
  50.  
  51.  
  52.  
  53. }
  54.  
  55. }
Add Comment
Please, Sign In to add comment