[Logo]
Forums Register Login
How to save file with condition in File IO java
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
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.
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
And welcome to the ranch.
 
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?
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?
i tried with


am not sure if this is the right way
Thanks for the greetings..Tony
This is the full code

 
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.



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.

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.
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..
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Oct 18, 2017 01:43:03.