JAVA读取文本文件并打印每行带引号的字符串

JAVA读取文本文件并打印每行带引号的字符串,java,arrays,string,sorting,Java,Arrays,String,Sorting,我应该读入一个文本文件,然后每行打印一个带引号的字符串。引用字符串的大小也必须相同 这是读取文件: "check on","SKY yelow, blue ocean","","1598" "6946","Jaming","Mountain range","GOOO, five, three!","912.3" 这是预期的产出: check on SKY yelow, blue ocean 1598 6946 jaming Mountain range GOOO, five, three! 9

我应该读入一个文本文件,然后每行打印一个带引号的字符串。引用字符串的大小也必须相同

这是读取文件:

"check on","SKY yelow, blue ocean","","1598"
"6946","Jaming","Mountain range","GOOO, five, three!","912.3"
这是预期的产出:

check on
SKY yelow, blue ocean
1598
6946
jaming
Mountain range
GOOO, five, three!
912.3
我知道如何读取文件,但如何获得如上所示的输出


提前谢谢

使用模式和匹配器类

List<String> lst = new ArrayList();
Matcher m = Pattern.compile("\"([^\"]+)\"").matcher(string);
while(m.find())
{
lst.add(m.group(1));
}
System.out.println(lst);
List lst=new ArrayList();
Matcher m=Pattern.compile(“\”([^\“]+)\”).Matcher(字符串);
while(m.find())
{
第一次添加(m组(1));
}
系统输出打印项次(lst);

您可以执行以下操作

Scanner scanner = new Scanner(new File("path"));
        String input = scanner.next();
        Pattern p = Pattern.compile("\"([^\"]*)\"");
        Matcher m = p.matcher(input);
        while (m.find()) {
            System.out.println(m.group(1));
        }

您可以从以下代码获取帮助:

String a = "\"abc\",\"xyzqr\",\"pqrst\",\"\"";   // Any string (of your specified type)
String an[] = a.split(",");
for (String b : an) {
      System.out.println(b.substring(1, b.length() - 1));
}

逐行读取数据并使用上述代码打印预期结果。

这里是从txt文件中读取数据的代码。这将按您的意愿打印,我在下面提到了包含该txt文件的数据

“维鲁”、“萨钦”、“德拉维德”、“甘古里”、“罗希特”


您可以使用Java字符串拆分。看这里:另外,在询问这里之前,您应该尝试更多…不知道
jeep
来自何处..@AvinashRaj感谢您捕捉到了这一点。编辑了输出。--这不起作用,因为我的读取文件中的一些引用字符串包含“,”。如果我们拆分“,“它将在引用的字符串中拆分这些单词以进行分隔。
import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;



    public class logic {

        public static void main(String[] args)
        {
            BufferedReader br = null;

            try {

                String sCurrentLine;
                br = new BufferedReader(new FileReader("C:/Users/rajmohan.ravi/Desktop/test.txt"));

                while ((sCurrentLine = br.readLine()) != null) {
                    reArrange(sCurrentLine.split(","));
                }

            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (br != null)br.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }
        public static void reArrange(String[] dataContent)
        {
            for(String data : dataContent)
            {
                System.out.print(data);
                System.out.print("\r\n");
            }
        }


    }