aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "PrintWriter questions" Watch "PrintWriter questions" New topic
Author

PrintWriter questions

shankar radhakrishnan
Greenhorn

Joined: Jan 14, 2001
Posts: 7
Hi,
I was trying to write to a file. It worked fine with
DataOutputStream p = new DataOutputStream(new FileOutputStream("Demo.txt"));
p.write("Hello");
This wrote "Hello" to file Demo.txt.
But when i did the following
PrintWriter p = new PrintWriter(new FileWriter("Demo.txt"));
p.write("Hello");
It did not write anything on to the file Demo.txt. Instead, a batch file was created with the following text
@ECHO OFF
C:
CD "\Java\JTips Mock Exams"
C:\jdk1.3\bin\java.exe input
PAUSE
The file name that i used was input.java 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
Shankar
Tony Alicea
Desperado
Sheriff

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


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

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.
Shankar
 
Consider Paul's rocket mass heater.
 
subject: PrintWriter questions