谁能帮我编个JAVA程序?

来源:百度知道 编辑:UC知道 时间:2024/05/14 12:36:05
题目如下: 编写一个程序WordCount, 统计一个或多个文件中的字数,文件的选取可以通过javax.swing.JFileChooser来实现,将统计的字数显示在文本框中。如果文件不存在,则弹出对话框提示信息。要求为每个文件启动一个新的线程。如输出结果:
address.txt:1025
report.txt:447
好的给高分,谢谢各位大大了!

public class WordCount {

public WordCount() {
new Thread(new WordCountThread()).start();
}

public static void main(String[] args) {
new WordCount();
}
}

public class WordCountThread implements Runnable {

private String path;
public void run() {

Scanner sc = new Scanner(System.in);
System.out.print("请输入文件的路径:");
path = sc.nextLine();
if(path != null)
{
String fpath = path.replace("\\", "\\\\");
File f = new File(fpath);
if(f.exists())
{
try {
//FileInputStream in = new FileInputStream(f);
InputStream i = new FileInputStream(f);
System.out.println(f.getName() +" : "+ i.available());
// BufferedInputStream br = new BufferedInputStream(i);
//DataInputStream d = new DataInputStream(i);
} catch (FileNot