Results 1 to 3 of 3
- 10-24-2008, 05:19 PM #1
Member
- Join Date
- Oct 2008
- Location
- London, England
- Posts
- 3
- Rep Power
- 0
newbie. Reading a file, deprecated method
I read and (for the sake of this example) print a file:
The Java documentation (can't post link) saysJava Code:File file = new File("fu.bar"); FileInputStream fis = null; DataInputStream dis = null; try { fis = new FileInputStream(file); dis = new DataInputStream(fis); while (dis.available() != 0) { System.out.println(">" + dis.readLine()+ "<"); }but if I do this the available() method isn't, ahem, available, and I can't see what the equivalent is. Help appreciated. Pointer to alternative method of reading file also appreciated.readLine() Deprecated. This method does not properly convert bytes to characters. As of JDK 1.1, the preferred way to read lines of text is via the BufferedReader.readLine() method. Programs that use the DataInputStream class to read lines can be converted to use the BufferedReader class by replacing code of the form:
DataInputStream d = new DataInputStream(in);
with:
BufferedReader d
= new BufferedReader(new InputStreamReader(in));
- 10-24-2008, 06:46 PM #2
BufferedReader returns null when it reaches the end–of–file.
Java Code:File file = new File("fu.bar"); BufferedReader br = null; try { br = new BufferedReader( new InputStreamReader( new FileInputStream(file))); String line; while ( (line = br.readLine()) != null ) { System.out.println(">" + line + "<"); }
- 10-24-2008, 08:08 PM #3
Member
- Join Date
- Oct 2008
- Location
- London, England
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
getYear deprecated method
By ravian in forum New To JavaReplies: 5Last Post: 01-05-2011, 08:50 AM -
deprecated method.. help!
By iuna in forum Java AppletsReplies: 11Last Post: 09-08-2008, 08:38 PM -
Right use of file reading ?
By jurka in forum New To JavaReplies: 3Last Post: 08-27-2008, 08:16 PM -
method size is deprecated
By oregon in forum New To JavaReplies: 4Last Post: 08-05-2007, 05:59 PM -
Newbie help with a file parser
By adlb1300 in forum New To JavaReplies: 2Last Post: 07-24-2007, 04:31 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks