Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

i/o about printwriter

 
gul khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mport java.io.*;
class Characters {
public static void main(String [] args) throws IOException{
char vChar;
PrintWriter out= new PrintWriter(new BufferedWriter(new FileWriter("Characters.txt")));
for (int i=33;i<255;i++) {
vChar=(char) i;
System.out.println("<Number :"+i+" In Character is: "+vChar+">");
String vString= "<Number :"+i+" In Character is: "+vChar+">";
out.write(vString);
}
}
this file produces output to consele and also creates file "Character.txt" but file is empty
i m unable to figure out why?
any comment.

 
nan sh
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You write vString= "" to file Characters.text, that is why file is empty. There is no doublt here,gul.
Try the following code, you can have i in file Characters.txt;
import java.io.*;
class Characters {
public static void main(String [] args) throws IOException{
char vChar;
PrintWriter out= new PrintWriter(new BufferedWriter(new FileWriter("Characters.txt")));
for (int i=33;i<255;i++) {
vChar=(char) i;
System.out.println("");
String vString = Integer.toString(i);
out.write(vString);
}
out.close();
}
}

 
gul khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello that line was mistake
i changed the code
<code>import java.io.*;
class Characters {
public static void main(String [] args) throws IOException{
char vChar;
PrintWriter out= new PrintWriter(new BufferedWriter(new FileWriter("Characters.txt")));
for (int i=33;i<255;i++) {
vChar=(char) i;
System.out.println("<Number :"+i+" In Character is: "+vChar+">");
String vString= "<Number :"+i+" In Character is: "+vChar+">";
out.write(vString);
}
}
this file produces output to consele and also creates file "Character.txt" but file is empty
i m unable to figure out why?
any comment.
see io it doent print anyway
i also used
String vString = Integer.toString(i);
file is created but nothing in it
</code>
any help

[This message has been edited by gul khan (edited March 03, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic