*
The moose likes Java in General and the fly likes How to save file with condition in File IO java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to save file with condition in File IO java" Watch "How to save file with condition in File IO java" New topic
Author

How to save file with condition in File IO java

ten chang
Greenhorn

Joined: Apr 05, 2013
Posts: 9
hey all
i am totally new to this forum and i am not sure if i am putting this quesiton in right segment. if i am not sorry for that . i can't seems to figure out how to save file. i have two file namely lower.txt and upper.txt. i can't figure how to give condition or say like if the user input is less than number 60 then save that file in lower.txt else in upper.txt. can anyone please suggest what kinda code to use and where in try n catch statement should put in ?
thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

Do you already know how to do basic file I/O?

If so, then all you need to do is apply the desired file name when you create the File instance.

if not, then the tutorial should get you going.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
ten chang
Greenhorn

Joined: Apr 05, 2013
Posts: 9
thanks for the quick response, i have all the user input in place the only problem was i couldn't redirect if the input has more than 60. i can only save in lower.txt
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2402
    
  50
And welcome to the ranch.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

ten chang wrote:thanks for the quick response, i have all the user input in place the only problem was i couldn't redirect if the input has more than 60. i can only save in lower.txt


So you don't know how to write an if statement?

Or you don't know how to test if some value is greater than 60?
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2402
    
  50
Please post your code (or as much as is relevant) so we can see what you are doing. Also what does " if the input has more than 60" mean. Are you talking about the ASCII value of a character?
ten chang
Greenhorn

Joined: Apr 05, 2013
Posts: 9
i tried with


am not sure if this is the right way
ten chang
Greenhorn

Joined: Apr 05, 2013
Posts: 9
Thanks for the greetings..Tony
This is the full code

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

ten chang wrote:i tried with


am not sure if this is the right way



And when you looked at the documentation for that write() call, it told you that the Writer will attach itself to the file name you pass, and write out whatever you're thinking of, without you telling it what to write?

Because that how you must think it behaves, based on what you said you're trying to do.



ten chang
Greenhorn

Joined: Apr 05, 2013
Posts: 9
To be honest i thought it's gonna write and save user input in either lower.txt or upper.txt. but i guess within the parameter should be things you want to write.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Not "within the parameter", no. Once you have a Writer, then you call methods of the Writer which output whatever you want to write. Since you have a BufferedWriter (not a bad choice), here's a link to a tutorial about how to do that.
ten chang
Greenhorn

Joined: Apr 05, 2013
Posts: 9
Thanks Paul.. after scratching my head whole lot of time finally made it worked... now i need to show the record one by one ... that i entered..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to save file with condition in File IO java