Hi

i have a requirement to read a text file where field positions are specified and make use of that data to insert into tables. Please refer to the data in the text file below

1234 HEDEPT 12-3-2009 12-03-2009 yesno yes A hello@hello.com 12 y12
1234 HEDEPT 12-3-2009 12-03-2009 yesno yes A hello@hello.com 12 y12

i am reading the text file using Filereader . please help me how to read the same making use of field positions.
emp id 1-4[fieldposition]
deptcode 4-12[fieldposition]

If you are reading the file line by line, and you are SURE that each line will have values separated by an empty String then you can use this example:

String line = "1234 HEDEPT 12-3-2009 12-03-2009 yesno yes A hello@hello.com 12 y12";

String [] tokens = line.split(" ");

// Now print the array and see what happens:
for (int i=0;i<tokens.length;i++) {
   System.out.println(i+":"+tokens[i]);
}

There is always the subString method you can use that is only when you know the the fields will have a fixed size. If the lines are like that use the split method:

1234 HEDEPT 12-3-2009 12-03-2009 yesno yes A hello@hello.com 12 y12
123 HEDEPTASD 12-3-2009 12-03-2009 yesno yes A bye@bye.com 12 y12
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.