如何读取二进制文件并在JTable中显示?
如何读取二进制文件并在jtable
中显示它?
从在Java中保存这样的文件的代码:
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {
int returnVal = jFileChooser.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
try {
File file = jFileChooser.getSelectedFile();
this.jTextField.setText(file.getAbsolutePath());
FileOutputStream fileOut = new FileOutputStream(file);
ObjectOutputStream out = new ObjectOutputStream(fileOut);
for(int i=0; i < tblSinhVien.getRowCount(); i++) {
for(int j=0; j<tblSinhVien.getColumnCount(); j++) {
out.writeObject(tblSinhVien.getValueAt(i, j));
}
}
out.close();
fileOut.close();
this.jTextField.setText("Đã lưu");
} catch(IOException e) {
Logger.getLogger(Student_JFrame.class.getName()).log(Level.SEVERE, null, e);
}
}
}
How can I read a binary file and display it in a JTable
?
From the code that saves the file like this in Java:
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {
int returnVal = jFileChooser.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
try {
File file = jFileChooser.getSelectedFile();
this.jTextField.setText(file.getAbsolutePath());
FileOutputStream fileOut = new FileOutputStream(file);
ObjectOutputStream out = new ObjectOutputStream(fileOut);
for(int i=0; i < tblSinhVien.getRowCount(); i++) {
for(int j=0; j<tblSinhVien.getColumnCount(); j++) {
out.writeObject(tblSinhVien.getValueAt(i, j));
}
}
out.close();
fileOut.close();
this.jTextField.setText("Đã lưu");
} catch(IOException e) {
Logger.getLogger(Student_JFrame.class.getName()).log(Level.SEVERE, null, e);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论