如何将文本区域转换为txt文件,但格式相同,因为我尝试将其转换为txt文件,但txt文件中的输出只是一条长行,而不是像文本一样在很多行上区域。
这是我的代码:
private void convertToTxtActionPerformed(java.awt.event.ActionEvent evt) {
//////not included on the generated datalogs///
String lastDevice = jLastDevice.getText();
String progname = jProgramName.getText();
String progRev = jProgramRevision.getText();
/////////////////////////////////////////////
String boardname = jBoardname.getText();
String pn = jPN.getText();
String sn = jSN.getText();
String boardrev = jBoardRev.getText();
String verifStatus = jVerificationStatus.getText();
String failedTNum = jFailedTNum.getText();
String checker = jFailingChecker.getText();
String tester = jTesterNumber.getText();
String remarks = jRemarks.getText();
String verifiedBy = jVerifiedBy.getText();
//String dLogs = jDatalog.getText();
try{
File file = new File("\\\\ets88-spare\\e\\Data Logs\\ " + sn + "_" + verifStatus + ".txt");
if(!file.exists()){
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write("Board Name : " + boardname);
bw.newLine();
bw.write("Part Number : " + pn);
bw.newLine();
bw.write("Serial Number : " + sn);
bw.newLine();
bw.write("Board Revision : " + boardrev);
bw.newLine();
bw.write("Failing Test Parameter : " + failedTNum);
bw.newLine();
bw.write("Failing Checker : " + checker);
bw.newLine();
bw.write("Verified By : " + verifiedBy);
bw.newLine();
bw.write("Remakrs : " + remarks);
bw.newLine();
bw.write("Tester Number : " + tester);
bw.newLine();
bw.write("**************************************************************************************");
bw.newLine();
bw.write("* Datalog *");
bw.newLine();
bw.write("**************************************************************************************");
bw.newLine();
bw.newLine();
for (String dLogs : jDatalog.getText().split("\\n")){
bw.write(dLogs);
System.out.println(dLogs);
}
bw.close();
String note = boardname.concat(" with ").concat(sn).concat(" is located on 'ETS88-spare'\'E:'\'Data Logs'"); //" with " + sn " is located on 'EData Logs'"
JOptionPane.showMessageDialog(null, note);
//System.out.println(note);
}catch(IOException | HeadlessException e) {
JOptionPane.showMessageDialog(null, e);
}
}