Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

write to output file

I want to write (integer,string,float,boolean) to output file how to create output file and who to write to it.
with regards
0
rana_m
Asked:
rana_m
1 Solution
 
functionpointerCommented:
why cant you

//say....
String str = "a string";
int i = 9;
float flt = 3.4;
boolean b = false;


FileWriter fw = new FileWriter( new File( "test" ) );
fw.write( i );
fw.write( str );
fw.write( flt );
fw.write( b );

fw.close();

?
0
 
kokchoon78Commented:
0
 
b612_foreverCommented:
Although FileWriter can work, I feel that PrintWriter is better.

try{

    PrintWriter pr = new PrintWriter(new BufferedWriter(new FileWriter("MyFile.txt")));                    
    pr.write(6);
    pr.write("String");
    pr.write(6.12);
    pr.print(false);
}catch(FileNotFoundException e){e.printStackTrace();}

I am not sure whether there is any IOException or not, test it yourself.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now