テキスト ファイルから読み取る Java プログラムがあり、変数を 2 つの文字列 ( "text" : " と " , "date の間) の間の文字列に設定しようとしています。 : -3'、私のコードに適用できる他の解決策が見つからないようです。
String filename5 = "C:\\Users\\Steven\\Desktop\\Tests\\wunderground
\\outputTweetsWeatherAlerts.txt";
String filename6 = filename5;
FileInputStream input_file5 = new FileInputStream(filename5);
Scanner input5 = new Scanner(input_file5);
input5.findInLine("\"id\"");
String tweetText1 = input5.next();
int startPosition = tweetText1.indexOf(": \"") + ": \"".length();
System.out.println("Start Position: " + startPosition);
int endPosition = tweetText1.indexOf("\" , \"date", startPosition);
System.out.println("endPosition " + endPosition);
String tweetText = tweetText1.substring(startPosition, endPosition);
// THIS LINE CAUSES ERROR: String index out of range: -3
System.out.println(tweetText);
私が読んでいるテキストファイルは次のとおりです。
{ "_id" : { "$oid" : "507dc77633f77fd20f7eec96"} , "id" : 258307760112955393 , "text" : "ランダムなテキスト" , "date" : { "$date" : ... }
どんな助けでも大歓迎です!ありがとう