Results 1 to 7 of 7
Thread: text file
- 10-04-2010, 11:41 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 3
- Rep Power
- 0
text file
i am trying to load a text file which is in my C: drive, but dont know what to enter for C://, plus theJava Code:package fileinput; import java.io.*; /** * * @autho */ public class Main { public Main () { } /** * @param args the command line arguments */ public static void main(String[] args) { try { FileInputStream fstream = new FileInputStream("data.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while((strLine = br.readline()) != null) { System.out.println(strLine); } in.close(); } catch(Exception e) { System.err.println("Error:" + e.getMessage() ); } } }
is stating Cant find Symbol. Symbol ReadLine() location class java.io.BufferedReaderJava Code:while((strLine = br.readline()) != null)
i take it this error is showing as it cant find the text file ? i have Data in the Text file when the program runs the file opens and whats inside the file should show up in the program.
- 10-04-2010, 11:52 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,544
- Rep Power
- 11
is stating Cant find Symbol. Symbol ReadLine() location class java.io.BufferedReader
What it's really saying is "Can't find Symbol. Symbol readline() location class java.io.BufferedReader". (In general copy, paste and post these messages so we can see them exactly as they are.)
This is because there is no readline() method in the BufferedReader class. Have a read of the BufferedReader API documentation and see what the method is really called.
- 10-05-2010, 12:19 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 3
- Rep Power
- 0
how to i add the dir of the text file into the
after i run itJava Code:FileInputStream fstream = new FileInputStream("data.txt");
debug:
Error:data.txt (The system cannot find the file specified)
BUILD SUCCESSFUL (total time: 8 seconds)
to fix the BufferedReader what should i enter?
I am using NetBean
cannot find symbol
symbol: method readline()
location: class java.io.BufferedReader
--
(Alt-Enter shows hints)
- 10-05-2010, 12:37 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,544
- Rep Power
- 11
Did you follow the link? It mentions 9 methods, one of which is the correct spelling for readline().
One way of specifying the file location is new FileInputStream("dir/data.txt") (note the use of a foward slash). More flexibly you could use the FileInputStream constructor that takes a File argument.
- 10-05-2010, 01:41 AM #5
Cross posted at Open Text file - Java Programming Forums
- 10-05-2010, 01:49 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,544
- Rep Power
- 11
Again! I won't claim that it's a case of great minds thinking alike. But it certainly looks like a case of a less great one unwilling to think at all.
@OP: you will be doing us all - yourself included - a favour if you are upfront about cross posting and provide a link (on both sites) as Norm has done for you. As with any conversation, people like to know what's being said.
And it is a conversation. So not only is it worth checking out a link if two people provide it, but it's also good form to reply to them if, again independently, they ask you a question.
- 10-05-2010, 03:41 AM #7
Member
- Join Date
- Oct 2010
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
textfield - printstream - text file - to much text
By keneid in forum New To JavaReplies: 2Last Post: 06-14-2010, 10:18 AM -
Combobox from plain text file (plain text file database)
By cotarelo in forum AWT / SwingReplies: 3Last Post: 06-08-2010, 08:10 PM -
count character in text file as input file
By aNNuur in forum New To JavaReplies: 7Last Post: 03-25-2010, 04:01 PM -
Insert text records from text file into a DB
By nicedad in forum JDBCReplies: 8Last Post: 11-06-2009, 06:52 AM -
find and replace text from a text file
By gezzel in forum New To JavaReplies: 2Last Post: 09-19-2008, 04:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks