请教各位高手,我学Java时间不长,现在遇到了一个问题。
从串口可以读出数据,但是我没办法把它存成文档,有没有什么解决方法吗?
老师催着要,先谢谢大家了
下面是部分程序:
public class SerialReader implements SerialPortEventListener{
InputStream in;
public SerialReader(InputStream in)
{
this.in = in;
}public void serialEvent(SerialPortEvent arg0)
{
int data;
try{ 
if((in.read())>-1){in.read(tmpBuffer, 0, 1024);}
System.out.println(new String(tmpBuffer,0,1024));
DataBuffer = tmpBuffer;
finish = true;
}catch (IOException e)
{
e.printStackTrace();
System.exit(-1);
}
//finish = true;
//DataBuffer = tmpBuffer;
}
}main.javapublic static void main(String[] args) {
// TODO Auto-generated method stubbyte[] myData = new byte[16];
try{
(new UARTIn("COM4")).startIO();
myData = new UARTIn().DataBuffer;
if((new UARTIn("COM4")).isFinish()){
(new UARTIn("COM4")).stopIO();
}
File file = new File("c:/uart.txt");
outFile.write(myData);  // 44 - the actual data itself - just a long string of numbers}
catch(Exception ex){
ex.printStackTrace();
}
}