read mutiple files :(

hello to all

i have prob. with read multiple files

and i dont know where is prob.:(

i com e here to help me ....

this is the code

privatestatic Vector<String[]> files=new Vector(0);

privatestatic String [] DF;

public A()throws FileNotFoundException{

File myDir =new File("C:/Ar");

String myfiles[] = myDir.list();

for (int i = 0; i < myfiles.length; i++){

System.out.println("processing file: " + myDir.getAbsolutePath() +"/" + myfiles[i]);

Scanner s =null;

try{

s =new Scanner(new BufferedReader(new FileReader(myfiles[i])));

int size=0;

System.out.println("\n\nhdf");

while (s.hasNext()){

try{

s.useDelimiter(" ");

DF[size]=s.next();

}

catch(Exception e){

}

size++;

}

files.addElement(DF);

s.close();

}

catch(Exception e){

}

}

}

[2101 byte] By [happy_paina] at [2007-11-27 3:22:32]
# 1
> catch(Exception e){>} Don't use empty catch blocks. You should at least print the stack trace.Kaj
kajbja at 2007-7-12 8:25:17 > top of Java-index,Java Essentials,Java Programming...
# 2
Uh ... What's the problem you're having? What is it doing or not doing that it's supposed to and what is it telling you. You'll probably have to take the other advice you've been given before you can begin to do this.PS.
puckstopper31a at 2007-7-12 8:25:17 > top of Java-index,Java Essentials,Java Programming...
# 3
I would like to add that you don't need to use Vectors.They are slow and have a lot of overhead.
maple_shafta at 2007-7-12 8:25:17 > top of Java-index,Java Essentials,Java Programming...
# 4
> I would like to add that you don't need to use Vectors.> > They are slow and have a lot of overhead.?
jTooheya at 2007-7-12 8:25:17 > top of Java-index,Java Essentials,Java Programming...
# 5

import java.io.BufferedReader;

import java.io.FileReader;

import java.util.Enumeration;

import java.util.Hashtable;

import java.util.Scanner;

import java.util.Vector;

import javax.swing.JOptionPane;

import java.io.File;

public class Arab1{

private static Hashtable table;

public Arab1() {

}

public static void main(String[] args) {

// TODO code application logic here

Vector<String[]> files=new Vector(0);

File myDir = new File("C:/Ar");

String myfiles[] = myDir.list();

for (int i = 0; i < myfiles.length; i++){

Scanner s =null;

try {

s = new Scanner(new BufferedReader(new FileReader(myDir.getAbsolutePath() + "/" + myfiles[i])));

int size=0;

String [] DF = null;

int q = 0;

while (s.hasNext()) {

try{

s.useDelimiter(" ");

DF[q]=s.next();

}

catch(Exception e){

}

q++;

}

files.addElement(DF);

s.close();

}

catch(Exception e){

e.printStackTrace();

}

}

int i=0;

table = new Hashtable();

for(int k=0; k<files.size();k++){

String [] DF=files.get(k);

for(int p=0;p<DF.length;p++){///// here the error

i=DF[p].length();

char Lo[]=DF[p].toCharArray();

int count=0;

for(int j=0;j<i;j++)

{

if(Lo[j]><1569 || Lo[j]>1610 ||Lo[j]>1590 &&Lo[j]<1592 || Lo[j]>1595 && Lo[j]<1601 ||Lo[j]=='َ' || Lo[j]=='ً' || Lo[j]=='ُ'

|| Lo[j]=='ٌ' || Lo[j]=='ِ' || Lo[j]=='ٍ' ||Lo[j]=='ّ' || Lo[j]=='ْ')

{

count++;

for(int h=j; h <i-1 ; h++)

Lo[h]=Lo[h+1];

i--;

j--;

}

}

int y=Lo.length-count;

//System.out.println(y);

String chars = new String(Lo);

String sub=chars.substring(0,y);

// System.out.println(sub);

if(y!=0){

if ( table.containsKey(sub ) ) {

Integer counter = (Integer) table.get(sub); // get value

// and increment it

table.put(sub, new Integer( counter.intValue() + 1 ) );

}

else // otherwise add the word with a value of 1

table.put(sub, new Integer( 1 ) );

}

}

}

String output = "";

Enumeration keys = table.keys();

while ( keys.hasMoreElements() ) {

Object currentKey = keys.nextElement();

// output the key-value pairs

System.out.print(currentKey+" ");

System.out.println(table.get(currentKey));

}

System.out.println(table.size());

System.out.println(table.isEmpty());

}

}

Exception in thread "main" java.lang.NullPointerException

at Arab1.main(Arab1.java:62)

Java Result: 1>

happy_paina at 2007-7-12 8:25:17 > top of Java-index,Java Essentials,Java Programming...
# 6
What's going on on line 62 of Arab1? Something on that line is trying to access a member of something that hasn't been initialized.PS.
puckstopper31a at 2007-7-12 8:25:17 > top of Java-index,Java Essentials,Java Programming...
# 7
for(int p=0;p<DF.length;p++){///// here the error i=DF[p].length();how can be inti.?Message was edited by: happy_pain>
happy_paina at 2007-7-12 8:25:17 > top of Java-index,Java Essentials,Java Programming...
# 8
Exception in thread "main" java.lang.NullPointerExceptionat Arab1.main(Arab1.java:62)so your Array is null , be sure its has elements ,
eaajea at 2007-7-12 8:25:17 > top of Java-index,Java Essentials,Java Programming...