我有一个这种格式的文件:
City|the Location|the residence of the customer| the age of the customer| the first name of the customer|
我只需要阅读第一行以确定符号“|”之间有多少个字符。我需要代码来读取空格。
这是我的代码:
`FileInputStream fs = new FileInputStream("C:/test.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fs));
StringBuilder sb = new StringBuilder();
for(int i = 0; i < 0; i++){
br.readLine();
}
String line = br.readLine();
System.out.println(line);
String[] words = line.split("|");
for (int i = 0; i < words.length; i++) {
int counter = 0;
if (words[i].length() >= 1) {
for (int k = 0; k < words[i].length(); k++) {
if (Character.isLetter(words[i].charAt(k)))
counter++;
}
sb = new StringBuffer();
sb.append(counter).append(" ");
}
}
System.out.println(sb);
}
`
我对java很陌生