我正在尝试创建一个 output.txt 文件,代码正在编译且没有错误,但没有创建 o/p 文件。请问有什么帮助吗?
import java.io.*;
public class StudentPoll_dasariHaritha {
public static void main( String args[] )
{
int frequency[] = new int[ 6 ];
try {
BufferedInputStream pollNumbers =
new BufferedInputStream( new FileInputStream( "numbers.txt" ) );
try {
// for each answer, use that value as subscript to
// determine element to increment
while( true ) {
++frequency[ pollNumbers.read() ];
}
}
catch( EOFException eof ) {
}
String output = "Rating\tFrequency\r\n";
// append frequencies to String output
for ( int rating = 1; rating < frequency.length; rating++ ) {
output += rating + "\t" + frequency[ rating ] + "\r\n";
}
BufferedWriter writer =
new BufferedWriter( new FileWriter( "output.txt" ) );
writer.write( output );
writer.close();
pollNumbers.close();
System.exit( 0 );
}
catch( IOException io ) {
System.exit( 1 );
}
有人可以解释一下这段代码没有创建输出文本文件吗?