可以說我有這有兩個字符串中的每一行的文本文件:如何檢查文本文件是否包含單個字符串或兩個字符串?
New York 52.523405 13.4114
San Antonio 41.387917 2.169919
Los Angeles 51.050991 13.733634
,這是我的代碼從線路輸出分割字符串:
for (int i = 0; i < noOfStores;i++){
nextLine = console.readLine();
nextLine = nextLine.trim();
String temp[] = nextLine.split(" ");
String Word = temp[0] + " " + temp[1];
storeNames[i] = firstWord;
latitudes[i] = Double.parseDouble(temp[2]);
longitudes[i] = Double.parseDouble(temp[3]);
}
但如果一個文本文件只包含一個字符串在這樣的每一行:
Berlin 52.523405 13.4114
Barcelona 41.387917 2.169919
Dresden 51.050991 13.733634
如何檢查一個文本文件中是否包含一個或閱讀時有兩個string?
請參閱更新的答案,包括代碼。 –