Java Code Examples for java.io.FileWriter#append()

The following examples show how to use java.io.FileWriter#append() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
String compile() throws IOException {

            // Create a class that references classId
            File explicit = new File("ExplicitClass.java");
            FileWriter filewriter = new FileWriter(explicit);
            filewriter.append("class ExplicitClass { " + classId + " implicit; }");
            filewriter.close();

            StringWriter sw = new StringWriter();

            com.sun.tools.javac.Main.compile(new String[] {
                    "-verbose",
                    option.optionString,
                    "-source", "8", "-target", "8",
                    "-sourcepath", Dir.SOURCE_PATH.file.getPath(),
                    "-classpath", Dir.CLASS_PATH.file.getPath(),
                    "-Xbootclasspath/p:" + Dir.BOOT_PATH.file.getPath(),
                    "-d", XPreferTest.OUTPUT_DIR.getPath(),
                    explicit.getPath()
            }, new PrintWriter(sw));

            return sw.toString();
        }
 
Example 2
Source Project: NClientV2   File: Queries.java    License: Apache License 2.0 6 votes vote down vote up
private static void dumpTable(String name,FileWriter sb) throws IOException{

            String query="SELECT * FROM "+ name;
            Cursor c=db.rawQuery(query,null);
            sb.write("DUMPING: ");
            sb.write(name);
            sb.write(" count: ");
            sb.write(""+c.getCount());
            sb.write(": ");
            if(c.moveToFirst()){
                do{
                    sb.write(DatabaseUtils.dumpCurrentRowToString(c));
                }while(c.moveToNext());
            }
            c.close();
            sb.append("END DUMPING\n");
        }
 
Example 3
Source Project: tsml   File: HiveCote.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static void genericCvResultsFileWriter(String outFilePathAndName, Instances instances, double[] preds, String datasetName, String classifierName, String paramInfo, double cvAcc) throws Exception{
    
    if(instances.numInstances()!=preds.length){
        throw new Exception("Error: num instances doesn't match num preds.");
    }
    
    File outPath = new File(outFilePathAndName);
    outPath.getParentFile().mkdirs();
    FileWriter out = new FileWriter(outFilePathAndName);
    
    out.append(datasetName+","+classifierName+",train\n");
    out.append(paramInfo+"\n");
    out.append(cvAcc+"\n");
    for(int i =0; i < instances.numInstances(); i++){
        out.append(instances.instance(i).classValue()+","+preds[i]+"\n");
    }
    out.close();
    
}
 
Example 4
protected void createCMISParametersFile() throws IOException
{
   	File f = File.createTempFile("OpenCMISTCKContext", "" + System.currentTimeMillis(), new File(System.getProperty("java.io.tmpdir")));
   	f.deleteOnExit();
   	FileWriter fw = new FileWriter(f);
   	for(String key : cmisParameters.keySet())
   	{
   		fw.append(key);
   		fw.append("=");
   		fw.append(cmisParameters.get(key));
   		fw.append("\n");
   	}
   	fw.close();
   	System.setProperty(JUnitHelper.JUNIT_PARAMETERS, f.getAbsolutePath());
   	System.out.println("CMIS client parameters file: " + f.getAbsolutePath());
}
 
Example 5
/**
     * Main method. When args.length > 0, clusterMaster method is triggered with 
     * args instead of the local main method. 
     * 
     * @param args
     * @throws Exception 
     */
    public static void main(String[] args) throws Exception{
        
        if(args.length>0){
            clusterMaster(args);
            return;
        }
        // else, local:
//        String problemName = "alphabet_raw_26_sampled_10";
        String problemName = "vowel_raw_sampled_10";
        
        StringBuilder instructionBuilder = new StringBuilder();
        for(ElasticEnsemble.ConstituentClassifiers c:ElasticEnsemble.ConstituentClassifiers.values()){
            scriptMaker_runCv(problemName, 0, c, instructionBuilder);
        }
        FileWriter out = new FileWriter("instructions_"+problemName+".txt");
        out.append(instructionBuilder);
        out.close();

    }
 
Example 6
/**
 * Test of getKeyCount method, of class MultiBundleStructure.
 */
@Test
public void testGetKeyCount() throws Exception {
    System.out.println("getKeyCount");
    File propFile = new File(getWorkDir(), "foo.properties");
    propFile.createNewFile();
    FileWriter wr = new FileWriter(propFile);
    wr.append("a=1\nb=2");
    wr.close();
    DataObject propDO = DataObject.find(FileUtil.toFileObject(propFile));
    assertTrue(propDO instanceof PropertiesDataObject);
    PropertiesDataObject dataObject = (PropertiesDataObject) propDO;
    MultiBundleStructure instance = new MultiBundleStructure(dataObject);
    instance.updateEntries();
    int expResult = 2;
    int result = instance.getKeyCount();
    assertEquals(expResult, result);
}
 
Example 7
Source Project: aws-sdk-java-v2   File: FileUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Appends the given data to the file specified in the input and returns the
 * reference to the file.
 *
 * @param dataToAppend
 * @return reference to the file.
 */
public static File appendDataToTempFile(File file, String dataToAppend)
        throws IOException {
    FileWriter outputWriter = new FileWriter(file);

    try {
        outputWriter.append(dataToAppend);
    } finally {
        outputWriter.close();
    }

    return file;
}
 
Example 8
Source Project: SLP-Core   File: IntsCreator.java    License: MIT License 5 votes vote down vote up
private static void write(FileWriter fw, List<String> tokens) throws IOException {
	for (String token : tokens) {
		fw.append(token);
		fw.append(" ");
	}
	fw.append(Vocabulary.EOS);
	fw.append("\n");
}
 
Example 9
private void writeRecordInfoCsvFile(FileWriter writer, ResultSet resultSet,
		int columnCount) throws SQLException, IOException {
	for (int i = 1; i <= columnCount; i++) {
		Object temp = resultSet.getObject(i);
		if (temp != null) {
			writer.append(temp.toString());
		}
		writer.append( VALUES_SEPARATOR );
	}
	writer.append("\n");
}
 
Example 10
Source Project: AndroidMuPDF   File: Logger.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 将日志信息写到本地文件中
 * 
 * @param tag 标签,也是存放日志的文件夹名
 * @param msg 内容
 */
private static void writeToFile(String tag, String msg) {
	if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
		try {
			String dir = mPath + tag + "/";
			
			Date now = new Date();
			SimpleDateFormat tempDate1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
			SimpleDateFormat tempDate2 = new SimpleDateFormat("yyyyMMdd", Locale.CHINA);
			String dateTime = tempDate1.format(now);
			String fileName = tempDate2.format(now);

			File destDir = new File(dir);
			if (!destDir.exists()) {
				destDir.mkdirs();
			}
			File file = new File(dir + fileName + ".txt");
			if (!file.exists()) {
				file.createNewFile();
			}
			FileWriter fw = new FileWriter(file, true);
			fw.append("\r\n=============" + dateTime + "=====================\r\n");
			fw.append(msg);
			fw.flush();
			fw.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
Example 11
Source Project: remoteyourcam-usb   File: PtpCamera.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void writeDebugInfo(File out) {
    try {
        FileWriter writer = new FileWriter(out);
        writer.append(deviceInfo.toString());
        writer.close();
    } catch (IOException e) {
    }
}
 
Example 12
public static void printIntensityTimeGraphInCSVFormat(List<XZ> values, String fileName) throws Exception {
  FileWriter chartWriter = new FileWriter(fileName);
  chartWriter.append("Intensity, Time");
  chartWriter.append(NEW_LINE_SEPARATOR);
  for (XZ point : values) {
    chartWriter.append(point.getIntensity().toString());
    chartWriter.append(COMMA_DELIMITER);
    chartWriter.append(point.getTime().toString());
    chartWriter.append(NEW_LINE_SEPARATOR);
  }
  chartWriter.flush();
  chartWriter.close();
}
 
Example 13
public  synchronized void addToReport(MSSQLTestData td, Object result) {
  System.out.println("called");
  try {
    FileWriter fr = new FileWriter(getResportFileName(), true);
    String offset = td.getData(KEY_STRINGS.OFFSET);
    String res = "_";
    if (result == null) {
    res = "Success";
  } else {
    try {
    res = "FAILED "
    + removeNewLines(((AssertionError) result)
    .getMessage());
    } catch (Exception ae) {
      if (result instanceof Exception
        && ((Exception) result) != null) {
        res = "FAILED "
        + removeNewLines(((Exception) result)
        .getMessage());
      } else {
        res = "FAILED " + result.toString();
      }
    }
  }

  fr.append(offset + "\t" + res + "\n");
  fr.close();
  } catch (Exception e) {
    LOG.error(StringUtils.stringifyException(e));
  }
}
 
Example 14
Source Project: netbeans   File: XMLLexerParserTest.java    License: Apache License 2.0 5 votes vote down vote up
private void assertContents(StringBuilder sb) throws IOException {
    File out = new File(getWorkDir(), fname + ".parsed");
    FileWriter wr = new FileWriter(out);
    wr.append(sb);
    wr.close();
    
    assertFile(out, getGoldenFile(fname + ".pass"), new File(getWorkDir(), fname + ".diff"));
}
 
Example 15
Source Project: AndroTickler   File: StartAttack.java    License: Apache License 2.0 5 votes vote down vote up
private synchronized void writeCommandInLogFile(String command){

		File logFile = new File(this.logFileName);
		String line="\n\n************************************ Tickler: Executing Command ************************************************\n"
		+command+"\n	 *******************************************************************************************************************\n\n";
		try{
			FileWriter w = new FileWriter(logFile,true);
			w.append(line);
			w.close();
		}
		catch (IOException e){
			e.printStackTrace();
		}
		
	}
 
Example 16
Source Project: ibm-cos-sdk-java   File: FileUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Appends the given data to the file specified in the input and returns the
 * reference to the file.
 * 
 * @param file
 * @param dataToAppend
 * @return reference to the file.
 * @throws IOException
 */
public static File appendDataToTempFile(File file, String dataToAppend)
        throws IOException {
    FileWriter outputWriter = new FileWriter(file);

    try {
        outputWriter.append(dataToAppend);
    } finally {
        outputWriter.close();
    }

    return file;
}
 
Example 17
Source Project: netbeans   File: TestUtilHid.java    License: Apache License 2.0 4 votes vote down vote up
public void serialize(String path, String tab, PrintWriter pw, File baseFolder) throws IOException {
    if (!getName().isEmpty()) {
        String n = getName();
        if (isLeaf()) {
            pw.print(tab+"<file name=\""+n + "\"");
        } else {
            pw.print(tab+"<folder name=\""+n + "\"");
        }
        String urlVal = null;

        if (fileContents != null) {
            urlVal = (path + getName()).replaceAll("/", "-");
            File f = new File(baseFolder, urlVal);
            FileWriter wr = new FileWriter(f);
            wr.append(fileContents);
            wr.close();
        } else if (contentURL != null) {
            urlVal = contentURL.toExternalForm();
        }
        if (urlVal != null) {
            pw.print(" url=\"" + urlVal + "\"");
        }
        pw.print(">");

        for (String s : attributeContents.keySet()) {
            pw.print("\n" + tab + "    <attr name=\"" + s + "\" " + 
                    attributeTypes.get(s) + "=\"" + attributeContents.get(s) + "\"/>");
        }
        pw.println();
    }
    String newPath = path + getName();
    if (!newPath.isEmpty()) {
        newPath = newPath + "/";
    }
    for (ResourceElement res : children.values()) {
        res.serialize(newPath, tab + "  ", pw, baseFolder);
    }
    if (!getName().isEmpty()) {
        if (isLeaf()) {
            pw.println(tab+"</file>" );                            
        } else {
            pw.println(tab+"</folder>" );            
        }
    }
}
 
Example 18
Source Project: java-n-IDE-for-Android   File: Actions.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Dump merging tool actions to a text file.
 * @param fileWriter the file to write all actions into.
 * @throws IOException
 */
void log(FileWriter fileWriter) throws IOException {
    fileWriter.append(getLogs());
}
 
Example 19
/**
 * This is always called on a single background thread.
 * Implementing classes must ONLY write to the fileWriter and nothing more.
 * The abstract class takes care of everything else including close the stream and catching IOException
 *
 * @param fileWriter an instance of FileWriter already initialised to the correct file
 */
private void writeLog(FileWriter fileWriter, String content) throws IOException {
    fileWriter.append(content);
}
 
Example 20
Source Project: javaide   File: Actions.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * Dump merging tool actions to a text file.
 * @param fileWriter the file to write all actions into.
 * @throws IOException
 */
void log(FileWriter fileWriter) throws IOException {
    fileWriter.append(getLogs());
}