Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

PrintWriter questions  RSS feed

 
shankar radhakrishnan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you flush and close P?
 
shankar radhakrishnan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!