0

我想阅读文件的整个文本,然后根据特定的分隔符将其拆分。我怎么能在Java中这样做?

4

2 回答 2

2
try{
  // Open the file
  FileInputStream fstream = new FileInputStream("textfile.txt");
  // Get the object of DataInputStream
  DataInputStream in = new DataInputStream(fstream);
  BufferedReader br = new BufferedReader(new InputStreamReader(in));
  String strLine;
  //Read File Line By Line
  while ((strLine = br.readLine()) != null)   {
  // split the line on your splitter(s)
     String[] splitted = strLine.split("-"); // here - is used as the delimiter
  }
  //Close the input stream
  in.close();
    }catch (Exception e){//Catch exception if any
  System.err.println("Error: " + e.getMessage());
  }
于 2012-12-08T07:21:50.130 回答
0

阅读内容。选择要检查每个行/单词或短语以进行拆分的分隔符。有一个开关盒设置。无论您根据 switch case 找到什么内容,都可以执行操作。假设您可以在不同情况下写入不同的文本文件。

于 2012-12-08T07:09:59.363 回答