Results 1 to 6 of 6
- 11-01-2007, 08:34 AM #1
Member
- Join Date
- Oct 2007
- Posts
- 21
- Rep Power
- 0
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.
- 11-01-2007, 12:29 PM #2
Member
- Join Date
- Nov 2007
- Location
- New Zealand
- Posts
- 36
- Rep Power
- 0
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)
I would recommend using JTextArea for using displaying editable text.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.
To better understand the purpose, pro's and con's of each stream: Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)
- 11-01-2007, 01:29 PM #3
Member
- Join Date
- Oct 2007
- Posts
- 21
- Rep Power
- 0
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
- 02-02-2010, 08:07 AM #4
Member
- Join Date
- Jan 2010
- Posts
- 90
- Rep Power
- 0
so can i use FileReader to read .csv and .text files?
- 02-02-2010, 08:36 AM #5
Member
- Join Date
- Nov 2007
- Location
- New Zealand
- Posts
- 36
- Rep Power
- 0
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!
- 02-02-2010, 09:06 AM #6
Member
- Join Date
- Jan 2010
- Posts
- 90
- Rep Power
- 0
Similar Threads
-
Writing an XML output
By JThangiah in forum XMLReplies: 2Last Post: 03-27-2008, 04:15 PM -
output
By Camden in forum New To JavaReplies: 3Last Post: 12-01-2007, 10:34 PM -
There's not enough memory to process the command. at java.io.FileInputStream
By mary in forum New To JavaReplies: 1Last Post: 08-03-2007, 06:17 PM -
Help with filereader in java
By zoe in forum Advanced JavaReplies: 2Last Post: 07-26-2007, 09:55 AM -
get the output from whoami
By gary in forum Advanced JavaReplies: 2Last Post: 06-12-2007, 01:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks