Results 1 to 6 of 6
  1. #1
    unhurt is offline Member
    Join Date
    Oct 2007
    Posts
    21
    Rep Power
    0

    Question FileReader Vs FileInputStream and same goes to output

    first things first im gona say hi being the new member to the forum(don't know if this is prerequisite or not) but anyway im wondering about those 2 IO method, what are their differences and when i should use them and also their advantage and disadvantage if there is such?



    Java Code:
    //read
    FileReader reader = null;
    try {
    	String fn1 = "Text1.txt";
    
    	FileReader reader = new FileReader(fn1);
    	txPane.read(reader, fn1);
    //Vs
    	FileInputStream fis = new FileInputStream(fn1);
    	txPane.read( fis, null );
    
    } catch (IOException exception) {
    	System.err.println("Load error");
    }
    Last edited by unhurt; 11-01-2007 at 08:40 AM.

  2. #2
    Turtle is offline Member
    Join Date
    Nov 2007
    Location
    New Zealand
    Posts
    36
    Rep Power
    0

    Default

    Hi Unhurt,

    FileReader (Java Platform SE 6)

    Convenience class for reading character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are appropriate. To specify these values yourself, construct an InputStreamReader on a FileInputStream.

    FileReader is meant for reading streams of characters. For reading streams of raw bytes, consider using a FileInputStream.

    FileInputStream (Java Platform SE 6)

    A FileInputStream obtains input bytes from a file in a file system. What files are available depends on the host environment.

    FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader.
    I would recommend using JTextArea for using displaying editable text.

    To better understand the purpose, pro's and con's of each stream: Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)

  3. #3
    unhurt is offline Member
    Join Date
    Oct 2007
    Posts
    21
    Rep Power
    0

    Default

    ah, i see, so basically filereader can only read whats on the surface? where as fileinputstream reads below that surface which can reads more than whats on the surface eh... great, thanks for sharing Turtle

  4. #4
    Cbani is offline Member
    Join Date
    Jan 2010
    Posts
    90
    Rep Power
    0

    Default

    so can i use FileReader to read .csv and .text files?

  5. #5
    Turtle is offline Member
    Join Date
    Nov 2007
    Location
    New Zealand
    Posts
    36
    Rep Power
    0

    Default

    Hi Cbani,

    You can use FileReader to read .csv and .txt files as both file types are files that contain characters.

    If you are using Excel to edit your csv file, try open it with notepad. You will see that each column is delimited by commas. Knowing this will help you read in data.

    To process a csv file you will want to access those values which are delimited by commas. The split method of the String class can archeive this: See String.split(String Regex)

    Alternatively, you could use the StringTokenizer class. StringTokenizer

    Best of luck!

  6. #6
    Cbani is offline Member
    Join Date
    Jan 2010
    Posts
    90
    Rep Power
    0

Similar Threads

  1. Writing an XML output
    By JThangiah in forum XML
    Replies: 2
    Last Post: 03-27-2008, 04:15 PM
  2. output
    By Camden in forum New To Java
    Replies: 3
    Last Post: 12-01-2007, 10:34 PM
  3. Replies: 1
    Last Post: 08-03-2007, 06:17 PM
  4. Help with filereader in java
    By zoe in forum Advanced Java
    Replies: 2
    Last Post: 07-26-2007, 09:55 AM
  5. get the output from whoami
    By gary in forum Advanced Java
    Replies: 2
    Last Post: 06-12-2007, 01:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •