前些阵自己用JAVA编写了一个KWIC的管道模式的程序,但是总是处理不了多行的输入(当你的输入文本是多行的时候,就只能处理第一行),单行的就可以,请大家看看,谢谢,哪位高手能帮忙解决下,十分的感谢!!代码如下(如果阅读不便请大家copy下来看看,不好意思!):
import java.lang.*;
import java.io.*;
import java.util.StringTokenizer;
public class KWIC_Pipe
{
public static void main(String[]args)
{
try
{
File file_1=new File( "C:\\Documents and Settings\\jesse\\桌面\\KWIC.txt ");//来源文件
FileReader words=new FileReader(file_1);
Reader KwicWords=sort(shift(words)); //先移位再排序
BufferedReader in=new BufferedReader(KwicWords);
File file_2=new File( "C:\\Documents and Settings\\jesse\\桌面\\KWIC_OUTPUT.txt ");//要将数据写到KWIC_OUTPUT.txt
PrintWriter outFile=new PrintWriter(new FileWriter(file_2));
String inputNew;
while((inputNew=in.readLine())!=null)
{
System.out.println( "结果: "+inputNew);
outFile.println(inputNew);
}
outFile.close();
in.close();
}
catch(IOException ex)
{
System.out.println(ex);
}
}
//移位方法
static Reader shift(Reader source)throws IOException
{
BufferedReader in=new BufferedReader(source);
PipedWriter pipeOut=new PipedWriter();
PipedReader pipeIn=new PipedReader(pipeOut);
PrintWriter out=new PrintWriter(pipeOut);
new ShiftThread(out,in).start();//启动线程做移位工作
return pipeIn;//移位的同时,不等移位结束就开始排序线程
}
//排序方法
static Reader sort(Reader source)throws IOException
{
BufferedReader in=new BufferedReader(source);
PipedWriter pipeOut=new PipedWriter();
PipedReader pipeIn=new PipedReader(pipeOut);
PrintWriter out=new PrintWriter(pipeOut);//建立一个向管道写入数据的PrintWriter实例
new SortThread(out,in).start();//启动线程做移位工作
return pipeIn;//线程启动后就返回不必等排序结束
}
}//class KWIC_Pipe end
//===========================================================================
class ShiftThread extends Thread
{
private PrintWriter out=null;
private BufferedReader in=null;
private int length;
private int i;
//constructor function
public ShiftThread(PrintWriter out,BufferedReader in)
{
this.out=out;
this.in=in;
}
public void run()
{
if(out!=null&&in!=null)
{
try
{
String input;
String shiftItStr;
while((input=in.readLine())!=null)
{
String[]string;
String[]string2;
StringTokenizer st=new StringTokenizer(input);
string=new String[st.countTokens()];
string2=new String[st.countTokens()];
length=st.countTokens();
//赋值
for(i=0;i <length;i++)
{