Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Newbie File Questions  RSS feed

 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry guys, I've forgotten all my File stuff. Been years.

I'm trying to:
1) Make a backup file of "pork.css", "pork.bak.css"
2) Open "pork.css" and write to it.

here's the basic approach I started.


Which results in:
I think I'm referencing the file wrong. What's the correct way to find the file?

[ June 16, 2006: Message edited by: Garrett Smith ]
[ June 16, 2006: Message edited by: Garrett Smith ]
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simply read the bytes from a FileInputStream and write them to an OutputStream. It is not necessary that you create the file for the OuputStream. It will be created automatically if it does not exist.

For instance, this code copies the bytes from an InputStream into a OutputSream:



You could invoke this code from any other method like this:

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!