: hi ,anyone can teach me how to read a row of data from a text file?
: i need to read the record in row and each row and each row have different type record,so i need to read the row and check which category it belongs to and only i add to the class.eg book ,tv,radio are record are added to different class.
:
: i need some example code about read from the text file.and the record are store in csv format.
: is this a way to do it ?
:
: import java.io.*;
:
: class ReadFromDesktop {
: public static void main(String [] args)throws IOException
: {
: String fs = java.io.File.separator;
: String ls = java.lang.System.getProperty("line.separator");
:
: File filePath = new File("C:"+fs+"Documents and Settings"+fs+"shiro"+fs+"Desktop"+fs+"readFromHere.txt");
:
: BufferedReader br = new BufferedReader(new FileReader(filePath));
:
: String data;
: data = br.readLine();
: while(data!=null)
: {
: System.out.println(data);
: data=br.readLine();
: }
: }
: }
:
I see you already read the rows from the file. Splitting the string into an array of strings can be done using the String.split() method, see
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#split(java.lang.String) for more info and example.
From there you can convert the individual string parts into the record fields.