• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

declaring array of vectors

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have a text file with following enteries:
12345 2145 0912
4356 0981 2134

now i want to declare the vector according to the number of lines the text file is containing,i wrote the following code but it didn't work:





//scalable sequential pattern mining

import java.io.*;
import java.util.*;
public class sspm
{

//static int numberofsequences;
//method for counting the number of sequences in the IBM data file
/*int count()

{
try
{
File f = new File("C:\\Program Files\\MyProjects\\final sspm\\sspm\\data1.txt");
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
LineNumberReader lnr = new LineNumberReader(br);
String line;



}

catch (IOException e)
{
e.printStackTrace();
}


return numberofsequences;
}*/
public static void main(String args[])
{

//Vector Transaction[] =new Vector();
//declaring array of transactions to hold individual transactions

//sspm s1=new sspm();
//int sequencesl=s1.count();

int numberofsequences=0;
try {



//vector for holding transactions
// files descriptors for accessing individual data files
File f = new File("C:\\Program Files\\MyProjects\\final sspm\\sspm\\data1.txt");

FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
LineNumberReader lnr = new LineNumberReader(br);
String line;
String temp[];

int spcount[] = new int[10];


//for counting the number of sequennces


while((line=br.readLine())!=null)
{
numberofsequences++;

}


//storing individual transactions in the array of vectors

System.out.println("total number of sequences in the data file are:"+numberofsequences);
File f1 = new File("C:\\Program Files\\MyProjects\\final sspm\\sspm\\data1.txt");
FileReader fr1 = new FileReader(f1);
BufferedReader br1 = new BufferedReader(fr1);
LineNumberReader lnr1 = new LineNumberReader(br1);
String line1;











Vector []transactions=new Vector[numberofsequences];

int index =0;
while((line1=br1.readLine())!=null &&index<=numberofsequences )
{
System.out.println(line1);
//numberofsequences--;
StringTokenizer st=new StringTokenizer(line1);



while (st.hasMoreElements( ))
{


String s1 = (String)st.nextElement();


transactions[index].add(s1);


//System.out.println("number of transactions in sequence "+ numberofsequences +" are "+ length);
//index++;
}

long length = transactions[index].size();
index++;
System.out.println("first vector size is"+length);



}
//System.out.println("total number of sequences in the data file are:"+numberofsequences);



} //end of try block

catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
}
//System.out.println(Transaction.size());
//System.out.println(Transaction.size());
}
}
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by fundupuneet vyas:
i wrote the following code but it didn't work:



In what way did it not work ? Does it compile (if not tell us what the error messages are - with an indication of which lines in your code they refer to). If it compiles but does not do what you wanted, then tell us what it is doing and how this differs from what you want it to do.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic