Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java I/O File code; how to read/write file

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Thanked 0 Times in 0 Posts

    Default Java I/O File code; how to read/write file

    I've been reading from Lesson: Basic I/O (The Java™ Tutorials > Essential Classes) but I don't understand the jargon very well without examples.

    What I'm trying to figure out how to do is read a file.

    I think this code will work for that: File inFile = new File(filelocation);

    The file should have texts which I'm trying to reorganize. On SQL, I would import the database, and parse out the information with case statements. I want to do the same with Java but I'm very unfamiliar with the code of Java.

    Can you give me an online source where I can find examples of how to read/edit text within a file?

  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Tavistock, UK
    Thanked 103 Times in 93 Posts

    Default Re: Java I/O File code; how to read/write file

    java.io.File is just a reference to a file, nothing more. To open a file for reading you need an InputStream for bytes or an InputStreamReader for characters. Most Java coders I know would use java.io.BufferedReader's readLine() method for line-at-a-time reading. There's a code fragment which is precisely what you want in the intro to BufferedReader in the API documentation:
    BufferedReader (Java Platform SE 6)

  3. The Following User Says Thank You to Sean4u For This Useful Post:

    ryu2le (September 18th, 2011)

Similar Threads

  1. Writing in a file using Java
    By JavaPF in forum File Input/Output Tutorials
    Replies: 4
    Last Post: December 17th, 2011, 04:33 PM
  2. Read a text file and parse the contents of file
    By HelloAll in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: March 3rd, 2011, 05:47 AM
  3. How to write to specific part of an html file using java
    By nasi in forum File I/O & Other I/O Streams
    Replies: 12
    Last Post: May 27th, 2010, 11:22 PM
  4. why does this code read an html file uncontinuously
    By nasi in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 25th, 2010, 09:09 PM
  5. Writing in a file using Java
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: August 13th, 2008, 06:45 AM