在这种情况下,我将如何使用定界符?

时间:2018-12-02 20:03:28

标签: java

我正在尝试编写代码,以提示用户打开给定目录的文件。文本文件中的数据摘录如下所示:

示例:

BAH,1、1

但是,我希望它像这样显示:

BAH

1

1

这是我遇到问题的地方。我如何使用定界符像上面的示例一样显示它?

这是我的代码:

 String s = "Aaaaa bbb cc dd dddd cc ttt d";
int x=  s.indexOf("cc")+1;
    for(int i=x;i<s.length();i++)
   {
     if(s.charAt(i)=='d')
     {s.replace(s.charAt(i),'');break;}
      }

这是提示用户输入文件目录的输出:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class TextUI {
    @SuppressWarnings("resource")
    public static void main(String[] args) throws IOException {
    String line = null;
    Scanner user = new Scanner (System.in);
    System.out.print("Please, Enter The File Directory Of The File You Want To Open:");

    //Input file
    String filename = user.nextLine();
    File input = new File(filename);
    Scanner scan = new Scanner(input);


     FileReader fileReader = new FileReader(filename);

     // BufferedReader reads the text from an Input stream (like a file) by buffering characters that seamlessly reads characters, arrays or lines. 
     BufferedReader bufferedReader = new BufferedReader(fileReader);


     while((line = bufferedReader.readLine()) != null) {
    System.out.println(line);
     }
     }
}

0 个答案:

没有答案