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){
}
}
}
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>