計算されたデータ レートの出力をファイルに保存しようとしています。データ レートは整数型で、ファイルに保存できず、次のエラーが発生します。
Exception in thread "main" java.io.IOException: Write error
at java.io.FileOutputStream.write(Native Method)
at java.io.DataOutputStream.write(Unknown Source)
at UDPSend.main(UDPSend.java:60)
コードは次のとおりです。
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public class UDPSend {
public static void main(String[] args) throws IOException
{
FileInputStream fstream = new FileInputStream("T.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String path="DataRateBefore.txt";
FileOutputStream f = new FileOutputStream(path);
DataOutputStream fo = new DataOutputStream (f);
InetAddress addr = InetAddress.getByName("localhost");
byte[] buf = new byte[10000];
String DataLine;
long lastTime = System.currentTimeMillis();
long firstTime = lastTime;
int nobits = 0;
long start = System.currentTimeMillis();
System.out.println("Start Time: " + start);
while ((DataLine = br.readLine()) != null)
{
DatagramPacket packet =new DatagramPacket(DataLine.getBytes(),DataLine.length() , addr, 4553);
System.out.println (DataLine);
DatagramSocket socket = new DatagramSocket();
socket.send(packet);
nobits+=packet.getLength() * 8;
System.out.println(packet.getLength());
System.out.println("no of bits is:");
System.out.println(nobits);
if ((System.currentTimeMillis() - lastTime) > 11)
{
lastTime = System.currentTimeMillis();
System.out.println("data rate is ");
System.out.println(nobits);
fo.write(nobits);
nobits= 0;
fo.close();
fo.flush();
}
}//end while loop
// Get the end time of the process
long end = System.currentTimeMillis();
System.out.println("End Time : " + end);
long elapsedTime = end - start;
// Show how long it took to finish the process
System.out.println("The process took approximately: " + elapsedTime + " milliseconds");
}//end main method
}
誰でもこれを解決するのを手伝ってもらえますか?