// writes the text area content to file private boolean writeToFile(String file, HashMap<String, ArrayList<Object>> map) { PrintWriter writer = rwFiles.getWriter(file); // writer to write to file // get data for each record int records = map.get(COL_APP).size(); // had to hard code - used app for (int i = 0; i < records; i++) { String app = ""; String title = ""; String rk = ""; String programmer = ""; String opened = ""; String closed = ""; String version = ""; String description = ""; if (map.get(COL_APP).get(i) != null) app = COL_APP + ": " + map.get(COL_APP).get(i).toString() + " "; if (map.get(COL_TITLE).get(i) != null) title = COL_TITLE + ": " + map.get(COL_TITLE).get(i).toString() + " "; if (map.get(COL_RK).get(i) != null) rk = COL_RK + ": " + map.get(COL_RK).get(i).toString() + " "; if (map.get(COL_PROGRAMMER).get(i) != null) programmer = COL_PROGRAMMER + ": " + map.get(COL_PROGRAMMER).get(i).toString() + " "; if (map.get(COL_DATE_OPENED).get(i) != null) opened = COL_DATE_OPENED + ": " + map.get(COL_DATE_OPENED).get(i).toString() + " "; if (map.get(COL_DATE_CLOSED).get(i) != null) closed = COL_DATE_CLOSED + ": " + map.get(COL_DATE_CLOSED).get(i).toString() + " "; if (map.get(COL_VERSION).get(i) != null) version = COL_VERSION + ": " + map.get(COL_VERSION).get(i).toString() + " "; if (map.get(COL_DESCRIPTION).get(i) != null) description = COL_DESCRIPTION + ": " + map.get(COL_DESCRIPTION).get(i).toString() + " "; /** * print to file FORMAT app title rk programmer opened closed version * ---------------------------------------------- descriptions */ writer.println(rk + app + title + programmer); writer.println("--------------------------------------------------------"); // break up the description from one long line to ten words per line String[] desc = description.split(" "); description = ""; for (int words = 0; words < desc.length; words++) { description += desc[words] + " "; if (words != 0 && words % 10 == 0) { writer.println(description); description = ""; } } writer.println(); // a line break between records } writer.flush(); writer.close(); return true; }
public boolean writeFromTextAreaToTextFile(TextAreaList textAreaList, String path) { PrintWriter writer = rwFiles.getWriter(path); // writer to write to file // for each text area list item for (CompIssuesItem item : compIssueItems) { String[] lines = item.getText().split("\n"); for (int i = 0; i < lines.length; i++) { writer.println(lines[i]); } writer.flush(); } writer.close(); return true; }
private void btnReadFromTextFileActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnReadFromTextFileActionPerformed fc.showOpenDialog(this); // file must be selected or null pointer is try { path = fc.getSelectedFile().getAbsolutePath(); // check first for null pointer BufferedReader reader = rwFiles.getReader(path); // textAreaCompiledOutputPane.setText(""); String line = reader.readLine(); while (line != null) { // textAreaCompiledOutputPane.append(line + "\n"); line = reader.readLine(); } } catch (NullPointerException e) { messageBox("Please select a file."); } catch (IOException ex) { messageBox(ex.getMessage()); } } // GEN-LAST:event_btnReadFromTextFileActionPerformed