[英]Splitting words from a text file
after,before,20
yes,no,9
所以我在文本文件上面有這些單詞,我想將它們分成不同的部分,以便我得到結果:
after
before
20
這是我的代碼
File files = new File("yes.txt");
Scanner in = new Scanner(files).useDelimiter("\\,");
String x = in.next();
String y = in.next();
String z = in.next();
System.out.println(x);
System.out.println(y);
System.out.println(z);
但結果是:
after
before
20
yes
我該怎么做才能刪除“是”?
再添加一個分隔符,使用" \\\\\\n "
過濾換行符
您需要將\\n
添加為分隔符,以便識別換行符。 現在它只承認,
作為一個分隔符:
Scanner in = new Scanner(files).useDelimiter(Pattern.compile("[,\\n]"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.