Έχω γράψει αυτήν την κλάση η οποία διαβάζει ένα text με προσφορές που σε κάθε του γραμμή έχει μία προσφορά η οποία περιλαμβάνει StoreName, ProductCategory, ProductName, ProductPrice, ProductDescription.. Μετά πρέπει να το χωρίζει σε λέξεις και να τις αποθηκεύει σε έναν πίνακα και τέλος μέσα στην ReadOffer να δίνει τιμές σε καθένα από τα παραπάνω και να τα αποθηκεύει στο αντικείμενο offers το οποίο και θα επιστρέφει.. Αλλά δεν μου τρέχει σωστά.. Μπορείτε να προτείνετε κάτι..?
package com.example.crazysellout.UserSide;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import com.example.crazysellout.Offer;
//Class that, reads the file of the data.
public class OfferDataReader {
String[] fileOnTable;
Offer ReadOffer(int indexLine){
Offer offers = new Offer();
offers.StoreName = fileOnTable[0];
offers.ProductCategory = fileOnTable[2];
offers.ProductName = fileOnTable[3];
offers.ProductPrice = fileOnTable[4];
offers.ProductDescription = fileOnTable[5];
return offers;
}
//initialize txt reader with the input stream to set fileOnTable
public OfferDataReader(InputStream iStream) throws IOException {
super();
this.readDataFile(iStream);
}
//Method that reads the text file from resources and
public void readDataFile(InputStream iStream) throws IOException {
//String that gets each line of the text file in a while loop
String stringContainer = null;
String strW= null;
//Variable in which the contex of the file will be stored
StringBuffer strBuffer = new StringBuffer();
//Reads each line from the file.
BufferedReader reader = new BufferedReader(new InputStreamReader(iStream));
while ((stringContainer = reader.readLine()) != null) {
strBuffer.append(stringContainer + "\n");
}
while ((strW = reader.readLine()) != null) {
strBuffer.append(strW + " ");
}
}
//Method that separates the string buffer to lines, and saves
//on a table so that they can be identified as an account.
public void textIndexOnTable(String indexOnString){
fileOnTable = indexOnString.split("\r\n|\r|\n");
}
public void lineInWords(String indexOnString){
fileOnTable = indexOnString.split(" ");
}
}