Write to a txt. file, via user input? (java with netbeans)
doug salls
Greenhorn
Joined: Feb 28, 2010
Posts: 8
posted
0
I am working on a read/write program that accesses information from said file..
Reading from it works.
I have been searching for a way to write to a file using using the input from a user.
I have ran into mostly code that is set to auto fill with predefined entries. Any help would be much appreciated.
Any bit of code, example, point in the right direction would be awesome..
I know scanner can read from files but i found nothing on it being able to write to text. files.
What i am not sure how to get around, is a bufferedwriter command for next entry to be written to my file.
Or if there is a better option for taking inputs and writing them to a file.
Write a string variable instead of a string constant?
Ireneusz Kordal
Ranch Hand
Joined: Jun 21, 2008
Posts: 423
posted
0
doug salls wrote:
What i am not sure how to get around, is a bufferedwriter command for next entry to be written to my file.
Just use another bw.write(....); command.
You may also write some separators between adjacent chunks of text (could be a new line or tabulation),
like this:
The above code writes three line of text to the file (\n is a 'new line').
doug salls
Greenhorn
Joined: Feb 28, 2010
Posts: 8
posted
0
Attempting to get the string variable working.. Problem i am running into as now is if the file is currently empty, even with the entry. Assuming i did it right. program crashes on me.
doug salls
Greenhorn
Joined: Feb 28, 2010
Posts: 8
posted
0
I am not sure why this is giving me so much grief. The arrays i set up for my last program were easy to work with and track.
TO my knowledge you cant pick say line 5 of a text file., and just println that information out. You would need to go through each line before it and once its reached said line you could have it set to print out only that data...
Its much easier to write to the arrays as well.. IMO.... head vs desk==Splat.
doug salls
Greenhorn
Joined: Feb 28, 2010
Posts: 8
posted
0
Its amazing what a little bit of sleep will do for you.... Figured it out thank you much for the input.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32644
4
posted
0
Welcome to the Ranch
Please find the Code button; since you are new I shall edit your code so you can see how much better it looks.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32644
4
posted
0
For full marks, you ought to tidy up your imports in that code.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Write to a txt. file, via user input? (java with netbeans)