Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to print the lines after writing them to an ouput file (java)
    primarykey
    data
    text
    <p>I have a problem. I'm basically asked to use a method to print from an output file. So to start off I actually began filling the output file with lines..then when I tried to actually read them and print them on the screen there was a slight problem. I actually used the 'debug' option and the problem turned out to be within the ' line = input.nextLine()' line of code but i don't really know why..I mean that's how we get to read from an output file...help would be appreciated.</p> <p>Here's my work so far:</p> <pre><code>import java.util.*; import java.io.*; public class Problem_3 { public static void main(String[] args) { PrintWriter outFile = null; File f1 = new File("try.txt"); try { outFile = new PrintWriter("try.txt"); outFile.println("First line!"); outFile.println("Second line!"); outFile.println("Third line!"); cat(f1); } catch (Exception e) { outFile.print("(1) Exception: " + e.getMessage()); // no such element exception } outFile.close(); } /* * outFile = new PrintWriter(f1); outFile.println("Line 1"); * outFile.println("Line 2"); outFile.println("Line 3"); outFile.print(""); * cat(f1); } catch (Exception e) { System.out.println("(1)Exception: " + * e.getMessage()); } outFile.close(); } */ public static void cat(File file) throws FileNotFoundException { Scanner input = null; String line = ""; input = new Scanner(new FileReader(file)); //line = input.next(); // line = input.nextLine();// this line calls the exception in the main method while ((line != null)) { System.out.println("In the while loop"); System.out.println("Line 323" + line); return; } input.close(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload