Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

write to a file

 
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey there,
If I use this:

how do I put the readChar bit into a file and save it for a rainy day? Or can I? I don't have a gui interface so I can't use getText() I just want what the user types in up until the user presses enter.
Thx in advance
J
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to capture an entire line of input you might consider wrapping a BufferedReader around your existing reader and using the readLine() method to capture input. Then you can store the input in a string and do with it as you please. That would look something like this:

To write the string to a file, you will need to open an outputStream and a writer to the file and then pass the string to the writer.
 
Jay Brass
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bodie - Dude,
Thanks a heap
It took a whole nite of typing and trying things while downloading as much as possible from napster.
But I finally got it to work. I couldn't however, get the writer bit to work. Here is what my code looks like PLEASE feel free to point out better ways or critism or mercilously mock it as you wish:

It ain't pretty but it works!
again thx
J
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jay, your code looked pretty good. I made some changes (most were stylistic) and got it to work. The problem that I seem to have with writing to files is that Windows NT doesn't recognize filenames as being relative. I have to specify a full path. If I don't, the file stream doesn't get created. There is probably something you can do with the string to indicate that it is relative to your JVM, but I don't really know what that would be, so I always give a full path and filename.
Anyway! Try this:

I hope this helps.
 
reply
    Bookmark Topic Watch Topic
  • New Topic