You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am getting an exception when I run the program given below. The input file is a text file containing the details of 500 tweets. JavaGoogleSpeechAPISample is a class which is the same as this: java-google-speech-api/src/main/java/com/darkprograms/speech/translator/GoogleTranslate.java . When I executed the program the first time, it managed to translate 19 tweets but when I tried executing it again, it immediately gave me this exception without translating any tweets. Please help me fix this issue.
packagegettingtweets3;
importjava.util.*;
importjava.util.regex.*;
importjava.io.*;
importjava.io.IOException;
publicclassTranslatingTweets4 {
publicstaticvoidmain(String[] args) throwsFileNotFoundException, IOException {
Scannerconsole = newScanner(System.in);
Scannerinput = checkFileName(console);
PrintStreamoutput = outputFile(console);
System.out.println();
while (input.hasNextLine()) {
Stringline = input.nextLine();
Patternpattern = Pattern.compile("^(.*?said:\\s*)(.*)$");
Matchermatcher = pattern.matcher(line);
if(matcher.find()) {
//Prints the offset after the last character matched.output.print(matcher.group(1));
Stringtweet = matcher.group(2);
// //Translate tweet by tweet// output.println(JavaGoogleSpeechAPISample.translate("en", tweet));//Translate word by wordScannertweetScan = newScanner(tweet);
while (tweetScan.hasNext()) {
Stringword = tweetScan.next();
output.print(JavaGoogleSpeechAPISample.translate("en", word) + " ");
}
output.println(); //for translating word by word
}
}
}
//Uses the given Scanner object to prompt the user for an input file name//until the user provides a valid input file name. Then returns a scanner//to read the contents of the input file.//Parameter needed:// console = a user-input scanner which prompts the user for an input file name// and reads the user's inputpublicstaticScannercheckFileName(Scannerconsole) throwsFileNotFoundException {
System.out.print("Input file name: ");
FileinputFile = newFile(console.nextLine());
while (!inputFile.canRead()) {
System.out.print("File not found. Try again: ");
inputFile = newFile(console.nextLine());
}
System.out.println();
returnnewScanner(inputFile);
}
//Uses the given Scanner object to prompt the user for an output file name.//Then returns a PrintStream to print the completed mad lib into the output file.//Parameter needed:// console = a user-input scanner which prompts the user for an output file name// and reads the user's inputpublicstaticPrintStreamoutputFile(Scannerconsole) throwsFileNotFoundException {
System.out.print("Output file name: ");
returnnewPrintStream(newFile(console.nextLine()));
}
}
Hi, I am getting an exception when I run the program given below. The input file is a text file containing the details of 500 tweets. JavaGoogleSpeechAPISample is a class which is the same as this: java-google-speech-api/src/main/java/com/darkprograms/speech/translator/GoogleTranslate.java . When I executed the program the first time, it managed to translate 19 tweets but when I tried executing it again, it immediately gave me this exception without translating any tweets. Please help me fix this issue.
@goxr3plus
The text was updated successfully, but these errors were encountered: