Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Reading text file need to ignore whitespace

  Asked By: Fabiana    Date: May 17    Category: Java    Views: 1608

i am reading a text file and inserting the data into a database.
the format of my text file is as follows:

item ID
stock level
reOrder level

i have no trouble reading the data in and inserting it into my DB.
however i wish to have a gap before the next lot of information in
the text file e.g.


item2 ID

here is my code:

statement = conn.createStatement();

try {
for(int i = 1; i < 3; i++) {
String in1 = bufferReader.readLine();
String in2 = bufferReader.readLine();
int in3 = Integer.parseInt(bufferReader.readLine());
int in4 = Integer.parseInt(bufferReader.readLine());
int in5 = Integer.parseInt(bufferReader.readLine());
String in6 = bufferReader.readLine();

query = "INSERT INTO Items(itemID, description, stockLevel,
reorderLevel, isReordered, reorderDate) VALUES('" + in1 + "', '" +
in2 + "', '" + in3 + "', '" + in4 + "', '" + in5 + "', '" + in6
+ "')";

}catch(Exception e) {
System.out.println("too many records");



1 Answer Found

Answer #1    Answered By: Kerry Wright     Answered On: May 17

Have you tried word boundaries using internationization and let JAVA do the work
for you?

Didn't find what you were looking for? Find more on Reading text file need to ignore whitespace Or get search suggestion and latest updates.