List of usage examples for java.io FileWriter append
@Override public Writer append(CharSequence csq) throws IOException
From source file:Interface.MainJFrame.java
private void btnCSVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCSVActionPerformed // TODO add your handling code here: FileWriter writer; try {/*w w w . j a va 2 s. c o m*/ writer = new FileWriter("output.csv"); writer.append("Name"); writer.append(','); writer.append("ID"); writer.append(','); writer.append("Phone"); writer.append(','); writer.append("Address"); writer.append(','); writer.append("Employee Type"); writer.append(','); writer.append("Pay Category"); writer.append(','); writer.append("Salary"); writer.append(','); writer.append("Hours"); writer.append(','); writer.append("Bonus"); writer.append(','); writer.append("Total"); writer.append('\n'); writer.append(txtFullName.getText()); writer.append(','); writer.append(txtEmployeeID.getText()); writer.append(','); writer.append(txtPhoneNumber.getText()); writer.append(','); writer.append(txtAddress.getText()); writer.append(','); writer.append(txtEmployeeType.getText()); writer.append(','); writer.append(txtPayCategory.getText()); writer.append(','); writer.append(txtSalary.getText()); writer.append(','); writer.append(txtHours.getText()); writer.append(','); writer.append(txtBonuses.getText()); writer.append(','); writer.append(txtTotal.getText()); writer.append('\n'); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:uk.org.openseizuredetector.OsdUtil.java
/** * Write data to SD card - writes to data log file unless alarm=true, * in which case writes to alarm log file. *//*from w ww . j a va2s . c o m*/ public void writeToLogFile(String fname, String msgStr) { Log.v(TAG, "writeToLogFile(" + fname + "," + msgStr + ")"); //showToast("Logging " + msgStr); Time tnow = new Time(Time.getCurrentTimezone()); tnow.setToNow(); String dateStr = tnow.format("%Y-%m-%d"); fname = fname + "_" + dateStr + ".txt"; // Open output directory on SD Card. if (isExternalStorageWritable()) { try { FileWriter of = new FileWriter(getDataStorageDir().toString() + "/" + fname, true); if (msgStr != null) { String dateTimeStr = tnow.format("%Y-%m-%d %H:%M:%S"); Log.v(TAG, "writing msgStr"); of.append(dateTimeStr + ", " + tnow.toMillis(true) + ", " + msgStr + "<br/>\n"); } of.close(); } catch (Exception ex) { Log.e(TAG, "writeToLogFile - error " + ex.toString()); showToast("ERROR Writing to Log File"); } } else { Log.e(TAG, "ERROR - Can not Write to External Folder"); } }
From source file:com.compomics.pladipus.controller.setup.InstallPladipus.java
/** * Writes an executable script to the desktop to start a worker * * @throws IOException//from w ww .ja v a 2 s . c om */ private void writeWorkerBash(String user, String password) throws IOException { String os = System.getProperty("os.name"); long maxMemory = Runtime.getRuntime().maxMemory(); int memory = (int) (0.9 * ((double) maxMemory / (double) (1024 * 1024))); String command = "java -Xmx" + memory + "m -Xms" + memory + "m -jar " + pladipusFolder + "/" + "Pladipus-execution-" + version + "/Pladipus-execution-" + version + ".jar -auto_pull -u " + user + " -p " + password; FileWriter bashWriter; if (os.toLowerCase().contains("windows")) { File bashFile = new File(System.getProperty("user.home") + "/Desktop/Pladipus-Worker.bat"); bashWriter = new FileWriter(bashFile); } else { File bashFile = new File(System.getProperty("user.home") + "/Desktop/Pladipus-Worker.sh"); bashWriter = new FileWriter(bashFile); } bashWriter.append(command).flush(); bashWriter.close(); }
From source file:au.org.ala.layers.grid.GridClassBuilder.java
private static void writeProjectionFile(String filename) { FileWriter spWriter = null; try {// w w w .j a v a 2 s .co m spWriter = new FileWriter(filename); StringBuffer sbProjection = new StringBuffer(); sbProjection.append("GEOGCS[\"WGS 84\", ").append("\n"); sbProjection.append(" DATUM[\"WGS_1984\", ").append("\n"); sbProjection.append(" SPHEROID[\"WGS 84\",6378137,298.257223563, ").append("\n"); sbProjection.append(" AUTHORITY[\"EPSG\",\"7030\"]], ").append("\n"); sbProjection.append(" AUTHORITY[\"EPSG\",\"6326\"]], ").append("\n"); sbProjection.append(" PRIMEM[\"Greenwich\",0, ").append("\n"); sbProjection.append(" AUTHORITY[\"EPSG\",\"8901\"]], ").append("\n"); sbProjection.append(" UNIT[\"degree\",0.01745329251994328, ").append("\n"); sbProjection.append(" AUTHORITY[\"EPSG\",\"9122\"]], ").append("\n"); sbProjection.append(" AUTHORITY[\"EPSG\",\"4326\"]] ").append("\n"); //spWriter.write("spname, longitude, latitude \n"); spWriter.append(sbProjection.toString()); spWriter.flush(); } catch (IOException e) { logger.error(e.getMessage(), e); } finally { if (spWriter != null) { try { spWriter.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } } } }
From source file:jetbrains.buildServer.vmgr.agent.Utils.java
public String executeAPI(String jSON, String apiUrl, String url, boolean requireAuth, String user, String password, String requestMethod, BuildProgressLogger logger, boolean dynamicUserId, String buildID, String workPlacePath) throws Exception { try {//from w ww. j a va 2s . c o m boolean notInTestMode = true; if (logger == null) { notInTestMode = false; } String apiURL = url + "/rest" + apiUrl; if (notInTestMode) { logger.message("vManager vAPI - Trying to call vAPI '" + "/rest" + apiUrl + "'"); } String input = jSON; HttpURLConnection conn = getVAPIConnection(apiURL, requireAuth, user, password, requestMethod, dynamicUserId, buildID, workPlacePath, logger); if ("PUT".equals(requestMethod) || "POST".equals(requestMethod)) { OutputStream os = conn.getOutputStream(); os.write(input.getBytes()); os.flush(); } if (conn.getResponseCode() != HttpURLConnection.HTTP_OK && conn.getResponseCode() != HttpURLConnection.HTTP_NO_CONTENT && conn.getResponseCode() != HttpURLConnection.HTTP_ACCEPTED && conn.getResponseCode() != HttpURLConnection.HTTP_CREATED && conn.getResponseCode() != HttpURLConnection.HTTP_PARTIAL && conn.getResponseCode() != HttpURLConnection.HTTP_RESET) { String reason = ""; if (conn.getResponseCode() == 503) reason = "vAPI process failed to connect to remote vManager server."; if (conn.getResponseCode() == 401) reason = "Authentication Error"; if (conn.getResponseCode() == 415) reason = "The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method. Check if you selected the right request method (GET/POST/DELETE/PUT)."; if (conn.getResponseCode() == 405) reason = "The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource. Check if you selected the right request method (GET/POST/DELETE/PUT)."; if (conn.getResponseCode() == 412) reason = "vAPI requires vManager 'Integration Server' license."; String errorMessage = "Failed : HTTP error code : " + conn.getResponseCode() + " (" + reason + ")"; if (notInTestMode) { logger.message(errorMessage); logger.message(conn.getResponseMessage()); } System.out.println(errorMessage); return errorMessage; } BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); StringBuilder result = new StringBuilder(); String output; while ((output = br.readLine()) != null) { result.append(output); } conn.disconnect(); // Flush the output into workspace String fileOutput = workPlacePath + File.separator + buildID + File.separator + "vapi.output"; FileWriter writer = new FileWriter(fileOutput); writer.append(result.toString()); writer.flush(); writer.close(); String textOut = "API Call Success: Output was saved into: " + fileOutput; if (notInTestMode) { logger.message(textOut); } else { System.out.println(textOut); } return "success"; } catch (Exception e) { e.printStackTrace(); logger.error("Failed: Error: " + e.getMessage()); return e.getMessage(); } }
From source file:dk.netarkivet.archive.arcrepositoryadmin.ReplicaCacheDatabaseTester.java
License:asdf
private File makeTemporaryFilelistFile() throws Exception { File res = new File(TestInfo.TEST_DIR, "filelist.out"); FileWriter fw = new FileWriter(res); StringBuilder fileContent = new StringBuilder(); fileContent.append("TEST1"); fileContent.append("\n"); fileContent.append("TEST2"); fileContent.append("\n"); fileContent.append("TEST3"); fileContent.append("\n"); fw.append(fileContent.toString()); fw.flush();// www . ja v a 2 s. c o m fw.close(); return res; }
From source file:nl.utwente.trafficanalyzer.Grouper.java
public static void groupFilesInFolder(Path dir) { FileWriter writer = null; try {/*from w w w. j av a 2 s.c o m*/ File folder = dir.toFile(); File[] listOfFiles = folder.listFiles(); Arrays.sort(listOfFiles); HashMap<String, List<File>> hmap = new HashMap<>(); System.err.println("sorting files..."); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { String streetname = listOfFiles[i].getName().split("_")[0]; if (hmap.keySet().contains(streetname)) { System.out.println("\tAdded new day for: " + streetname); hmap.get(streetname).add(listOfFiles[i]); } else { List<File> newList = new ArrayList<File>(); newList.add(listOfFiles[i]); hmap.put(streetname, newList); System.out.println("\tAdded new road : " + streetname); } } } System.err.println("generating csvs..."); for (String street : hmap.keySet()) { System.out.println("generating file: " + dir.toString() + "\\" + street + ".csv"); writer = new FileWriter(dir.toString() + "\\" + street + ".csv"); for (int i = 0; i < hmap.get(street).size(); i++) { List list = readCsvFile(hmap.get(street).get(i)); for (Object line : list) { CSVRecord record = (CSVRecord) line; for (int j = 0; j < 6; j++) { writer.append(record.get(j)); writer.append(','); } //end line writer.append('\n'); } } writer.flush(); writer.close(); } } catch (IOException ex) { Logger.getLogger(Grouper.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.apache.accumulo.minicluster.MiniAccumuloCluster.java
/** * @param config/*from www .jav a 2 s.co m*/ * initial configuration */ public MiniAccumuloCluster(MiniAccumuloConfig config) throws IOException { this.config = config.initialize(); config.getConfDir().mkdirs(); config.getAccumuloDir().mkdirs(); config.getZooKeeperDir().mkdirs(); config.getLogDir().mkdirs(); config.getWalogDir().mkdirs(); config.getLibDir().mkdirs(); if (config.useMiniDFS()) { File nn = new File(config.getAccumuloDir(), "nn"); nn.mkdirs(); File dn = new File(config.getAccumuloDir(), "dn"); dn.mkdirs(); File dfs = new File(config.getAccumuloDir(), "dfs"); dfs.mkdirs(); Configuration conf = new Configuration(); conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, nn.getAbsolutePath()); conf.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY, dn.getAbsolutePath()); conf.set(DFSConfigKeys.DFS_REPLICATION_KEY, "1"); conf.set("dfs.support.append", "true"); conf.set("dfs.datanode.synconclose", "true"); conf.set("dfs.datanode.data.dir.perm", MiniDFSUtil.computeDatanodeDirectoryPermission()); String oldTestBuildData = System.setProperty("test.build.data", dfs.getAbsolutePath()); miniDFS = new MiniDFSCluster(conf, 1, true, null); if (oldTestBuildData == null) System.clearProperty("test.build.data"); else System.setProperty("test.build.data", oldTestBuildData); miniDFS.waitClusterUp(); InetSocketAddress dfsAddress = miniDFS.getNameNode().getNameNodeAddress(); dfsUri = "hdfs://" + dfsAddress.getHostName() + ":" + dfsAddress.getPort(); File coreFile = new File(config.getConfDir(), "core-site.xml"); writeConfig(coreFile, Collections.singletonMap("fs.default.name", dfsUri).entrySet()); File hdfsFile = new File(config.getConfDir(), "hdfs-site.xml"); writeConfig(hdfsFile, conf); Map<String, String> siteConfig = config.getSiteConfig(); siteConfig.put(Property.INSTANCE_DFS_URI.getKey(), dfsUri); siteConfig.put(Property.INSTANCE_DFS_DIR.getKey(), "/accumulo"); config.setSiteConfig(siteConfig); } else { dfsUri = "file://"; } File siteFile = new File(config.getConfDir(), "accumulo-site.xml"); writeConfig(siteFile, config.getSiteConfig().entrySet()); FileWriter fileWriter = new FileWriter(siteFile); fileWriter.append("<configuration>\n"); for (Entry<String, String> entry : config.getSiteConfig().entrySet()) fileWriter.append("<property><name>" + entry.getKey() + "</name><value>" + entry.getValue() + "</value></property>\n"); fileWriter.append("</configuration>\n"); fileWriter.close(); zooCfgFile = new File(config.getConfDir(), "zoo.cfg"); fileWriter = new FileWriter(zooCfgFile); // zookeeper uses Properties to read its config, so use that to write in order to properly escape things like Windows paths Properties zooCfg = new Properties(); zooCfg.setProperty("tickTime", "2000"); zooCfg.setProperty("initLimit", "10"); zooCfg.setProperty("syncLimit", "5"); zooCfg.setProperty("clientPort", config.getZooKeeperPort() + ""); zooCfg.setProperty("maxClientCnxns", "1000"); zooCfg.setProperty("dataDir", config.getZooKeeperDir().getAbsolutePath()); zooCfg.store(fileWriter, null); fileWriter.close(); File nativeMap = new File(config.getLibDir().getAbsolutePath() + "/native/map"); nativeMap.mkdirs(); File testRoot = new File( new File(new File(System.getProperty("user.dir")).getParent() + "/server/src/main/c++/nativeMap") .getAbsolutePath()); if (testRoot.exists()) { for (String file : testRoot.list()) { File src = new File(testRoot, file); if (src.isFile() && file.startsWith("libNativeMap")) FileUtils.copyFile(src, new File(nativeMap, file)); } } }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.fragments.EventGeneratorFragment.java
private void writeStringToLogFileCPU(String text) { File root = Environment.getExternalStorageDirectory(); File file = new File(root, "EventGeneratorLogFileCPU.txt"); try {//w ww . j ava2 s .c om if (!file.exists()) file.createNewFile(); FileWriter filewriter = new FileWriter(file, true); filewriter.append(text); filewriter.close(); } catch (IOException e) { Toast.makeText(getActivity().getApplicationContext(), "Unable to write file: " + e.toString(), Toast.LENGTH_SHORT).show(); e.printStackTrace(); } }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.fragments.EventGeneratorFragment.java
private void writeStringToLogFileMem(String text) { File root = Environment.getExternalStorageDirectory(); File file = new File(root, "EventGeneratorLogFileMem.txt"); try {// w w w . j a v a2s . c o m if (!file.exists()) file.createNewFile(); FileWriter filewriter = new FileWriter(file, true); filewriter.append(text); filewriter.close(); } catch (IOException e) { Toast.makeText(getActivity().getApplicationContext(), "Unable to write file: " + e.toString(), Toast.LENGTH_SHORT).show(); e.printStackTrace(); } }