Import the Java. IO. *;
Public class Ex10_7 {
Public static void main (String args []) {
The File fRead=new File (" English. TXT ");//input source
EnglishCount. TXT File fWrite=new File (" ");//output destination
Try {
Writer out=new FileWriter (fWrite);//points to the destination output stream
BufferedWriter bufferWrite=new BufferedWriter (out);//create a BufferedWriter object, pass the Writer's instance out
Reader in=new FileReader fRead ();//input source input stream
BufferedReader bufferRead=new BufferedReader (in);//create a BufferedReader object, pass the Reader in the instance of the
String str=null;
While ((STR=bufferRead readLine ())!=null) {
StringTokenizer fenxi=new StringTokenizer (STR);//create the analysis method of the analytic words
Int count=fenxi. CountTokens ();
STR=STR + "number of words in the sentence" + count;
BufferWrite. Write (STR);
BufferWrite. NewLine ();//newLine is to write a file back to the way for
}
BufferWrite. Close ();//close the upper output flow first, then close the underlying flow
out.close();
In=new FileReader fWrite ();
BufferRead=new BufferedReader (in);
String s=null;
System. The out. Println (fWrite. GetName () + ":");
While ((s=bufferRead. ReadLine ())!=null) {
System.out.println(s);
}
BufferRead. Close ();//close the upper input stream and the underlying input stream
in.close();
}
The catch (IOException e) {
System. The out. Println (e. oString ());
}
}
}
Compiled using DOS operation no problem running error
Java. IO. FileNotFoundException: English. TXT (the system cannot find the specified file,)
The files I also put in a folder
O bosses to solve it
CodePudding user response:
DDDDDDDDDDDDDCodePudding user response: