Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.Scanner;
- import java.io.FileNotFoundException;
- import java.lang.String;
- public class FractionDemo extends Fraction {
- public static void main(String[] args) {
- StringBuilder sb = new StringBuilder();
- BufferedReader br = null;
- Scanner fileInput = new Scanner(System.in);
- System.out.println("Please make sure your text file is in your src folder and\n"
- +"enter your file name\n" + "Example:Lab1_InputFile.txt");
- String nameOfFile = fileInput.next();
- try {
- br = new BufferedReader(new FileReader("src/" + nameOfFile));
- String line;
- while ((line = br.readLine()) != null) {
- if (sb.length() > 0) {
- sb.append("\n");
- }
- sb.append(line);
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- if (br != null) {
- br.close();
- }
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- String contents = sb.toString();
- System.out.println(contents);
- }
- }
Add Comment
Please, Sign In to add comment