Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Obtain specified file content  RSS feed

 
suz crumless
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there, i'm fairly new to java and haven't really got a grasp of it yet. I'm trying to obtain the content of a file specified by the user. I Realise this is done through use of the file.io package, but thats about as far as i've got!! Can anyone show me how to do this, i would really appreciate the help, thanx

Suz
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not clear from your question where, and in what form, you want the file content to end up. But here are some pointers.

Make a java.io.File object from the file path.

Make a FileInputStream (for binary content) or a FileReader (for text) from your File.

Use the readXXX() method(s) of the stream or reader to read the content.

A hint for text files is that you can make it easy to read one line of text at a time, by wrapping a BufferedReader around your FileReader. Buffered readers and streams sometimes give better performance, too.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!