複数のスレッドを使用して 2 つのファイルを読み取り、ファイルの内容をコンソールに出力する必要があります。ユーザーはファイル パスを入力し、スレッドを使用してファイルの内容を読み取ります。ファイルを理解するのに苦労しています。run メソッドで何をすべきかを誰かに提案してもらえますか?
import java.io.*;
public class Ch3Ex4 implements Runnable
{
public void ReadFile(String str,Thread thread)
{
try
{
File inputFile = new File(str);
FileInputStream in = new FileInputStream(inputFile);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void run()
{
}
public static void main (String[] args)
{
try
{
Ch3Ex4 obj = new Ch3Ex4();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the two file paths:");
String s1 = br.readLine();
String s2 = br.readLine();
Thread thread1 = new Thread(obj);
Thread thread2 = new Thread(obj);
obj.ReadFile(s1, thread1);
obj.ReadFile(s2, thread2);
thread1.start();
thread2.start();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}