Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to save file with condition in File IO java

 
ten chang
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64608
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ten chang
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2936
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the ranch.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2936
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried with


am not sure if this is the right way
 
ten chang
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the greetings..Tony
This is the full code

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 20713
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic