Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

put a line to a text file

Status
Not open for further replies.

welldefined

Programmer
Mar 9, 2006
62
GB
Hi,

I tried to put a line into a text file without success:
try
{
FileWriter fw = new FileWriter("out.txt");
BufferedWriter bw = new BufferedWriter(fw);
}
catch(IOException e)
{
}
bw.write("inputed a line: ");
It said "bw cannot be resolved".
Just learnt how to get a line from a text file, I thought I might be able to input a line to a text file in a similar way.....

 
Code:
 catch(IOException e)
        {        
        }
Well that's like creating a fire-alarm-button which silently does nothing when getting hit.

The worst code I've seen this week.

You refuse to find out what the system is trying to tell you, but ask a forum!

How much easier it would be to print a stacktrace here!

seeking a job as java-programmer in Berlin:
 
OK, it steel shows the error message after adding something in the catch clause:
try
{
FileWriter fw = new FileWriter("out.txt");
BufferedWriter bw = new BufferedWriter(fw);
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
bw.write("inputed a line: ");
 
Your "bw" object is not within scope.
Please have a read of Java 101 :
These kind of questions are a bit basic, and are avoidbale after reading some basic programming material.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Yes, you are right!
Now, no error message. However, nothing would be put to the out.txt file by this code:

try
{
FileWriter fw = new FileWriter("out.txt");
BufferedWriter bw = new BufferedWriter(fw);
bw.write("inputed a line: ");
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
 
and you need to flush the stream

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top