私のタスクは、プロセスを作成することで(もネストした ディレクトリの)言葉は、ディレクトリ内のすべてのファイルを数える検索するプログラムを書くことだったかthreads.Iは、プロセスを作成するために必要とされたか、Javaプログラムでスレッドのカウント各ファイルのスレッド、 このプロセスまたはスレッドは、ファイル内の単語数をカウントします。プロセスまたはスレッド がカウントを終了すると、ファイル名とこのファイル内にいくつの単語が書き込まれます。 の末尾には、すべてのファイルについて合計数の単語が表示されます。私は次のエラーを取得していたプログラムを実行した後Wordが
package cloudS;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.File;
public class WordCount1
{
private static int count = 0;
public static void main (String [] args)
{
String path = "C:\\Users\\$mit\\Desktop";
path = path + "\\" + args[0];
String filename = args[0];
task1(filename, path);
task2(filename, path);
System.out.println("Total Word " + count);
}
public static void task2 (String filename, String path)
{
File file = new File (path);
if (file.isDirectory())
{
String [] name = file.list();
String [] paths = new String [name.length];
for (int i=0; i<name.length; i++)
{
paths[i] = path + "\\" + name[i];
task2(name[i], paths[i]);
}
}
else
{
BufferedReader br = null;
FileReader fr = null;
int wordCount = 0;
try
{
fr = new FileReader(path);
br = new BufferedReader (fr);
String line = null;
while ((line = br.readLine()) != null)
{
String [] array = line.split(" ");
wordCount = wordCount + array.length;
count = count + array.length;
}
}
catch (IOException e)
{
System.out.println("IOException");
}
System.out.println (filename + "\t" + wordCount);
try
{
br.close();
fr.close();
}
catch (IOException e)
{
System.out.println("IOException");
}
}
}
public static void task1 (String filename, String path)
{
BufferedReader br = null;
FileReader fr = null;
int wordCount = 0;
try
{
fr = new FileReader(path);
br = new BufferedReader (fr);
String line = null;
while ((line = br.readLine()) != null)
{
String [] array = line.split(" ");
wordCount = wordCount + array.length;
}
}
catch (IOException e)
{
System.out.println("IOException");
}
System.out.println (filename + "\t" + wordCount);
try
{
br.close();
fr.close();
}
catch (IOException e)
{
System.out.println("IOException");
}
}
}
: は私の仕事のために私は次のプログラムを作っcloudS.WordCount1.mainで0 (:スレッドで 例外「メイン」java.lang.ArrayIndexOutOfBoundsException WordCount1.java:15は)
すべてのヘルプはあなたがプログラムに引数を渡すました
あなたのスレッドはどこですか? –