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:");
}
}

Recommended Answers

All 2 Replies

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'

Line 7 is the worst error a human can make :)
This won't help but I suggest to you that you go through "The Java Tutorials" (http://docs.oracle.com/javase/tutorial/) once. :P :D :) :P

commented: like you were never a nOOb, dont keep putting others down, just because you think bad of their code -2
commented: Agree -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.