我需要使用多个线程读取两个文件并在控制台中打印文件的内容。用户将输入文件路径并使用线程读取文件的内容。我很难理解文件。谁能建议我在运行方法中应该做什么?
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();
}
}
}