?
Solved

write to output file

Posted on 2003-03-19
3
Medium Priority
?
203 Views
Last Modified: 2010-03-31
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
Comment
Question by:rana_m
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Expert Comment

by:functionpointer
ID: 8171993
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
 
LVL 4

Expert Comment

by:kokchoon78
ID: 8171994
0
 
LVL 1

Accepted Solution

by:
b612_forever earned 60 total points
ID: 8172069
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question