1

I have a large file which has 10,000 rows and each row has a date appended at the end. All the fields in a row are tab separated. There are 10 dates available and those 10 dates have randomly been assigned to all the 10,000 rows. I am now writing a java code to write all those rows with the same date into a separate file where each file has the corresponding rows with that date.

I am trying to do it using string manipulations, but when I am trying to sort the rows based on date, I am getting an error while mentioning the date and the error says the literal is out of range. Here is the code that I used. Please have a look at it let me know if this is the right approach, if not, kindly suggest a better approach. I tried changing the datatype to Long, but still the same error. The row in the file looks something like this: Each field is tab separated and the fields are:

business id, category, city, biz.name, longitude, state, latitude, type, date

**

qarobAbxGSHI7ygf1f7a_Q ["Sandwiches","Restaurants"] Gilbert Jersey Mike's Subs -111.8120071 AZ 3.5 33.3788385 business 06012010

** The code is:

    File f=new File(fn);
    if(f.exists() && f.length()>0)
    {
    BufferedReader br=new BufferedReader(new FileReader(fn));
    BufferedWriter bw = new BufferedWriter(new FileWriter("FilteredDate.txt"));

        String s=null;
        while((s=br.readLine())!=null){
            String[] st=s.split("\t");

            if(Integer.parseInt(st[13])==06012010){ 

Thanks a lot for your time..

Jose Luis
  • 3,307
  • 3
  • 36
  • 53
KRN
  • 15
  • 4

2 Answers2

0

i suggest not to use split, but rather use

String str = s.subtring(s.lastIndexOf('\t'));

in any case, you try to take st[13] when i see you only have 9 columns. might be you just need st[8]

one last thing, look at this post to learn what 06012010 really means

Community
  • 1
  • 1
No Idea For Name
  • 11,411
  • 10
  • 42
  • 70
0

Try this,

List<String> sampleList = new ArrayList<String>();
        sampleList.add("06012012");
        sampleList.add("06012013");
        sampleList.add("06012014");
        sampleList.add("06012015");

//

//

    String[] sampleArray = s.split(" ");
                if (sampleArray != null)
                {
                    String sample = sampleArray[sampleArray.length - 1];

                    if (sampleList.contains(sample))
                    {
                        stringBuilder.append(sample + "\n");
                    }
                }
newuser
  • 8,338
  • 2
  • 25
  • 33