Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading and Writing a file  RSS feed

 
c york
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a java beginner and have no idea on how to read and write a file in java. I have created different methods ex. getFile, readFile.... and used the filename as the parameter. Help, I am lost...
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Ultimately, you use the java.io.FileReader or java.io.FileInputStream class, depending on whether you're reading text or non-text data. Here is the chapter of Sun's Java Tutorial about files and other I/O topics -- lots of simple examples.
 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i know for beginners java.io can be quite tricky to understand (so many classes and wrappers etc.).

a good way to understand this library is by comparing it to design patterns. see: decorator and java.io.
if you're not into design patterns, give it a try. lots of apis are much easier to understand and your code-design (if not over-pattern-engineered) gets improved.

for beginners i really recommend: Head First Design Patterns from oreilly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!