Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        6年前关闭。
                                                                                            
                
        
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class Example {

public static void main(String[] args) throws IOException
{
File fis=new File("D:/Testcode/Test.txt");
BufferedReader br;
String input;
String var = null;
if(fis.isAbsolute())
{
br=new BufferedReader(new FileReader(fis.getAbsolutePath()));
while ((input=br.readLine())!=null) {
var=input;
}
}
//String var="Duminy to Warner, OUT, Duminy gets a wicket again. He has been breaking...
if(var!=null)
{
String splitstr[]=var.split(",");
if(splitstr[0].contains("to"))
{
String ss=splitstr[0];
String a[]=ss.split("\\s+");
int value=splitstr[0].indexOf("to");
System.out.println("Subject:"+splitstr[0].substring(0,value));
System.out.println("Object:"+splitstr[0].substring(value+2));
System.out.println("Event:"+splitstr[1]);
int count=var.indexOf(splitstr[2]);
System.out.println("Narrated Information:"+var.substring(count));
}
}
}
}


上面的程序显示了以下输出:
主题:Duminy
对象:华纳
事件:OUT
旁白信息:杜米妮再次获得了检票口。他一直在挣扎...

我的问题是,该文本可能包含示例“ Dumto to Warner,OUT,Duminy又得到了一个检票口。他一直在挣扎……”意味着,上述程序不会显示如上所示的输出。检查条件的空间

最佳答案

您可以这样阅读,但不鼓励这样做。照顾自己。

    File read=new File("D:\\Test.txt");
    BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(read),Charset.forName("UTF-8")));
    String news = reader.readLine();
    news = news.replace(",", "");
    String[] names = news.split(" ", 6);

    System.out.println("First String : "+names[0]+" "+names[1]);
    System.out.println("Second String : "+names[3]);
    System.out.println("Third String : "+names[4]);
    System.out.println("Fourth String : "+names[5]);

10-01 03:11