编辑我的代码和问题,我将 BufferedWriter 更改为类对象并初始化它
public static String filename = "frequencies.txt";
public static BufferedWriter bufferedWriter;
{
try
{
bufferedWriter = new BufferedWriter( new FileWriter( filename ) );
}
catch ( IOException e )
{
e.printStackTrace();
}
}
private void plot_Frequencies ( final ITraceDetails msg )
{
byte[] signal = msg.getFieldValue( "_Decoder Message" ).data();
int[] frequencies = new int[ 32 ];
try
{
for ( int i = 0, j = 29; i < frequencies.length; i++, j += 2 )
{
int low = signal[ j ] & 0xFF;
int high = signal[ j + 1 ] & 0xFF;
frequencies[ i ] = low | ( high << 8 );
this.Frequencies.add( createGTSXYDataItem( msg.getMsgIndex(), msg.getMsgIndex(), msg.getExtendedMid(), frequencies[ i ] ), false );
}
write_Frequencies( frequencies, band_number, bufferedWriter );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
private void write_Frequencies ( final int[] frequencies, final int band, final BufferedWriter writer ) throws IOException
{
try
{
// Start writing to the output stream
System.out.print( Arrays.toString( frequencies ) );
System.out.print( "\n" );
writer.write( "Hello World" );
writer.write( Arrays.toString( frequencies ) );
writer.newLine();
}
catch ( FileNotFoundException ex )
{
ex.printStackTrace();
}
catch ( IOException ex )
{
ex.printStackTrace();
}
}
现在它不会向文件打印任何内容,它只是创建一个空的 frequencie.txt 文件