我必须从 S/W 版本、供应商等二进制文件中读取数据。我必须在 textarea 中显示输出。读取配置后,usre 可以通过串行端口发送选定的文件。我在这里写了一些代码:
InputStream is=null;
try {
File urt=filebrowser.getSelectedFile();
is = new FileInputStream(urt);
DataInputStream in = new DataInputStream(is);
long l=urt.length();
char[] bytes= new char[(int)l];
int o=bytes.length;
errlabel.setText(String.valueOf(o));
String content;
int offset;
BufferedReader br = new BufferedReader(new InputStreamReader(in));
int numRead;
try {
br.read(bytes, 0, 46);
while ((content = br.readLine()) != null) {
StringBuilder sb=new StringBuilder(content);
jTextArea1.setText(sb.toString());
errlabel.setText(""+sb.length());
}
} catch (IOException ex) {
Logger.getLogger(MyBoxUpdator.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (FileNotFoundException ex) {
Logger.getLogger(MyBoxUpdator.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
is.close();
} catch (IOException ex) {
Logger.getLogger(MyBoxUpdator.class.getName()).log(Level.SEVERE, null, ex);
}
}
和输出
EE��6**UT�h��}�(:�萢Ê�*:�茢���_��(RQ��N���S��h����rMQ��(_Q����9mTT��\�nE�PtP�!E�UtBߌz��z���������
可能有什么问题?