in line 7 I have three errors.
TextFieldOutputDemo.java:7 '.class' expected (where it points to 't' in "throws")
FileOutputStream(String, boolean)throws FileNotFoundException;

TextFieldOutputDemo.java:7 ';' expected (where it points to 't' in "throws")
FileOutputStream(String, boolean)throws FileNotFoundException;

TextFieldOutputDemo.java:7 not a statement (where it points to 'F' in "FileNotFoundException")
FileOutputStream(String, boolean)throws FileNotFoundException;

import java.io.*;
public class TextFieldOutputDemo{
public static void main(String [] args){
BufferedReader br = new BufferedReader (new System.in());
PrintWriter OutputStream = null;
try{
FileOutputStream(String, boolean)throws FileNotFoundException;
OutputStream = new PrintWriter (new FileOutputStream("Sample.txt", true));
}
catch (FileNotFound e){
System.out.println("Error opening file");
System.exit(0);
}
System.out.println("Enter text:");
String line = null;
int ctr;
for(ctr = 1; ctr<=3; ctr++){
line = br.readLine();
OutputStream.println(ctr + "	" + line);
}
OutputStream.close();
System.out.println("Lines that have been written:");
}
}

Edited 4 Years Ago by thefifthhjohn: n/a

you should take a look where you are allowed to put a throws statement:

<AccessModifier> <ReturnType> methodName(<MethodParams>) throws ExceptionThatMightBeThrownInThisMethod{
<MethodBody>
}

also, since you are working in your main method: don't add a throws clause, or put a throw ...Exception in your code.

The main method is the very last place where you can catch and/or handle with an exception. try that code again, without the 'throws FileNotFoundException'

Edited 4 Years Ago by stultuske: n/a

This article has been dead for over six months. Start a new discussion instead.