我尝试在选择保存按钮后在表单端启动.txt文件的保存。保存将在业务包上进行。但是,它似乎并没有起作用。我无法弄清楚原因。以下是我在表单方面的内容:
private void jMnuSaveActionPerformed(java.awt.event.ActionEvent evt) {
statusMessageLabel.setText("");
JFileChooser f = new JFileChooser(".");
String path = "";
f.setDialogTitle("Save Asset Depreciation File");
FileNameExtensionFilter filter = new FileNameExtensionFilter ("Text File (*.txt)", "txt");
f.setFileFilter(filter);
JDialog dg = new JDialog();
int rval = f.showSaveDialog(dg);
if (rval == f.CANCEL_OPTION){
statusMessageLabel.setText("Open canceled.");
}
else if (rval == f.APPROVE_OPTION){
path = f.getSelectedFile().getName();
a.setSave(path);
statusMessageLabel.setText(path);
}
}
以下是我在业务包/资产类方面的内容:
public boolean setSave(String p){
boolean result = true;
try{
PrintWriter out = new PrintWriter(
new FileWriter(p + ".txt", true));
out.println("Asset Name: " + this.AssetNm);
out.println("Salvage value: " + this.salvage);
out.println("Cost: " + this.cost);
out.println("Life (years): " + this.life);
out.close();
}catch (IOException e){
result = false;
this.emsg = "Write status error: " + e.getMessage();
}
return result;
}