나는 차후에 사용할 수 있도록 작성된 청구서를 자바에 저장해야하는 의료 청구 소프트웨어를 만들고 있습니다. 파일이 불안정합니다. 프로그램을 실행할 때마다 절약되지 않습니다. 내 파일을 저장하기위한 더 나은 플랫폼이 무엇인지 알려주는 것도 좋습니다. 텍스트 파일에 법안을 저장하는의료 청구서를 자바의 .txt 파일에 작성하십시오.
내 코드 파일은 때때로으로 어떤 정보가없는 것은 아니다 때로는 저장지고 다음
final JButton cmdSave = new JButton("Save Bill to File");
cmdSave.setBounds(240,300,180,25);
cmdSave.setFont(f14);
cmdSave.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e)
{
try
{
File file = new File("c:/Bill.txt");
// if file doesnt exists, then create it
if (!file.exists())
{
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
Date today = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("dd MMMMM yyyy");
SimpleDateFormat formatter1 = new SimpleDateFormat("h:mm a");
bw.write("G.D.Enterprise");
bw.newLine();
bw.write("Date: " + formatter.format(today));
bw.newLine();
bw.write("Time: " + formatter1.format(today));
bw.newLine();
bw.newLine();
bw.write("Residence number: 033 2522 - 4738");
bw.newLine();
bw.write("Office number: 033 2521-5254");
bw.newLine();
bw.write("Office Address: 175/A Laketown, Block - A, Kolkata- 700054");
bw.newLine();
ComboBoxModel model = cmboSerial.getModel();//Serial number combobox
ComboBoxModel model1 = cmbo1.getModel();//Batch no combobox
ComboBoxModel model2 = cmbo2.getModel();//Quantity combobox
ComboBoxModel model3 = cmbo3.getModel();//Description combobox
ComboBoxModel model4 = cmbo4.getModel();//Rate combobox
ComboBoxModel model5 = cmbo5.getModel();//VAT?TAX combobox
ComboBoxModel model6 = cmbo6.getModel();//Dicount combobox
ComboBoxModel model7 = cmbo7.getModel();//Amount combobox
int size = model.getSize();
for(int i=0;i<size;i++) {
Object element = (String) model.getElementAt(i);//Serial number combobox
Object element1 = (String) model1.getElementAt(i);//Batch no combobox
Object element2 = (String) model2.getElementAt(i);//Quantity combobox
Object element3 = (String) model3.getElementAt(i);//Description combobox
Object element4 = (String) model4.getElementAt(i);//Rate combobox
Object element5 = (String) model5.getElementAt(i);//VAT?TAX combobox
Object element6 = (String) model6.getElementAt(i);//Discount combobox
Object element7 = (String) model7.getElementAt(i);//Amount combobox
bw.newLine();
bw.write((String) element + ") ");
bw.write((String) element3);
bw.newLine();
bw.write("Batch number = " + (String) element1);
bw.newLine();
bw.write("Rate = Rs." + (String) element4);
bw.newLine();
bw.write("Quantity = " + (String) element2);
bw.newLine();
bw.write("Dicount = Rs." + (String) element7);
bw.newLine();
bw.write("VAT/TAX = Rs." + (String) element5);
bw.newLine();
bw.write("Vat amount = Rs." + (Integer.parseInt((String) element5)) * (Integer.parseInt((String) element2)));
bw.newLine();
bw.newLine();
bw.write("Amount = " + (String) element7);
bw.newLine();
bw.newLine();
}
bw.write("Amount to be paid = Rs." + cmbo8.getText());
bw.newLine();
bw.close();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
});
같다. 누구든지이 문제에서 나를 도울 수 있습니까? 사전에 당신을 감사하십시오
'try-catch'의'finally' 섹션에'bw.close' 호출을 넣는 것으로 시작하십시오. 이렇게하면 오류가있는 경우 파일이 닫힙니다. 'File # createNewFile' 호출의 이유를 볼 수는 없지만 그게 저의 것입니다 ... – MadProgrammer
개인적으로 송장 번호와 함께 각 청구서를 생성하는 데 사용 된 모든 데이터를 저장하는 데이터베이스의 테이블 아이디어가 마음에 듭니다. . 그런 다음 특정 필드를 검색하여 특정 청구서를 찾아서 다시 인쇄 할 수 있습니다. 이 방법은 손실되거나 덮어 쓰기가 어려우며 검색하기 어려운 텍스트 파일을 사용하는 것보다 db를 사용하는 것이 훨씬 쉽습니다. –
다음과 같이 Java Properties를 사용할 수 있습니다. http://docs.oracle.com/javase/tutorial/essential/environment/properties.html – Adrian