This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes PrintWriter questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "PrintWriter questions" Watch "PrintWriter questions" New topic

PrintWriter questions

shankar radhakrishnan

Joined: Jan 14, 2001
Posts: 7
I was trying to write to a file. It worked fine with
DataOutputStream p = new DataOutputStream(new FileOutputStream("Demo.txt"));
This wrote "Hello" to file Demo.txt.
But when i did the following
PrintWriter p = new PrintWriter(new FileWriter("Demo.txt"));
It did not write anything on to the file Demo.txt. Instead, a batch file was created with the following text
CD "\Java\JTips Mock Exams"
C:\jdk1.3\bin\java.exe input
The file name that i used was and i was working in this directory c:\Java\JTips Mock Exams. I dont know why this was happening. Thanks in advance.
I am using jdk1.3
Tony Alicea

Joined: Jan 30, 2000
Posts: 3226
Did you flush and close P?

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
shankar radhakrishnan

Joined: Jan 14, 2001
Posts: 7
Thanks Alicea. I did not flush and close previously. I did add p.flush and p.close this time. It did write to the file. But it still creates the batch file. Thanks for your help.
I agree. Here's the link:
subject: PrintWriter questions
jQuery in Action, 3rd edition