Example usage for java.io FileWriter write

List of usage examples for java.io FileWriter write

Introduction

In this page you can find the example usage for java.io FileWriter write.

Prototype

public void write(int c) throws IOException 

Source Link

Document

Writes a single character.

Usage

From source file:com.testmax.util.FileUtility.java

public static void createTextFile(String absolute_path, String text) {
    System.out.println("Creating text file at: " + absolute_path);
    WmLog.getCoreLogger().info("Creating text file at: " + absolute_path);
    try {//  w ww.  j  a  v a  2 s .c om
        FileWriter file = new FileWriter(new File(absolute_path));
        file.write(text);
        file.close();
        WmLog.getCoreLogger().info("Saved text file at: " + absolute_path);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        WmLog.getCoreLogger().info("Problem occured while saving the HTML Report file html_report.html for "
                + absolute_path + " " + e.getMessage());
    }

}

From source file:android.databinding.tool.MakeCopy.java

private static void addFromFile(File resDir, File resTarget) {
    for (File layoutDir : resDir.listFiles(LAYOUT_DIR_FILTER)) {
        if (layoutDir.isDirectory()) {
            File targetDir = new File(resTarget, layoutDir.getName());
            for (File layoutFile : layoutDir.listFiles(XML_FILENAME_FILTER)) {
                File targetFile = new File(targetDir, layoutFile.getName());
                FileWriter appender = null;
                try {
                    appender = new FileWriter(targetFile, true);
                    appender.write("<!-- From: " + layoutFile.toURI().toString() + " -->\n");
                } catch (IOException e) {
                    System.err.println("Could not update " + layoutFile + ": " + e.getLocalizedMessage());
                } finally {
                    IOUtils.closeQuietly(appender);
                }//from w w  w . j  a  va2  s .  c o m
            }
        }
    }
}

From source file:com.bigtester.ate.tcg.controller.TrainingFileDB.java

/**
 * Clean test csv file.//from   w  ww .j ava2  s .c  o  m
 *
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static void cleanTestCsvFile() throws IOException {
    // initialize FileWriter object

    // FileSystemResource testFile = new
    // FileSystemResource(UserInputsTrainer.TESTFILE);

    FileWriter fileWriter = new FileWriter(UserInputsTrainer.TESTFILE);
    fileWriter.write("");
    fileWriter.close();

}

From source file:au.org.ala.layers.util.BatchConsumer.java

private static void writeToFile(String filename, String string, boolean append) throws IOException {
    FileWriter fw = new FileWriter(filename, append);
    fw.write(string);
    fw.close();//  w w  w. j  a v  a  2 s . com
}

From source file:com.teotigraphix.caustk.utils.RuntimeUtils.java

/**
 * Saves the String data to the File.//www  .j  a  v  a  2  s  .  co  m
 * 
 * @param file The location to save the String.
 * @param data The String data to save.
 * @throws IOException
 */
public static final void saveFile(File file, String data) throws IOException {
    FileWriter writer = null;
    try {
        writer = new FileWriter(file);
        writer.write(data);
    } catch (IOException e) {
        throw e;
    } finally {
        writer.close();
    }
}

From source file:io.github.seanboyy.lotReset.json.ReadJSON.java

/**Read JSON file by using configuration file's JSON value,
 * which points to the file//  ww  w  .j a  va 2s  .c  o  m
 * @param configLocation String which specifies the location of the config.properties file
 * @return <code>ArrayList&ltArrayList&ltLot&gt&gt lots</code> if no errors are encountered
 * @since 1.0 - Implemented config.properties in 2.0
 */
public static ArrayList<ArrayList<Lot>> read(String configLocation) {
    JSONParser parser = new JSONParser();
    URL url;
    File f;
    //lots is multidimensional in this format: {{fromLot,toLot},{fromLot,toLot},{fromLot,toLot},etc...}
    ArrayList<ArrayList<Lot>> lots = new ArrayList<ArrayList<Lot>>();
    Config config = ReadConfig.read(configLocation);
    final String[] alphabet = config.getAlpha();
    final String[] types = config.getType();
    final String[] worlds = config.getWorld();
    try {
        url = new URL(config.getJSON());
        InputStream in = url.openStream();
        f = File.createTempFile("temp", "json");
        FileWriter file = new FileWriter(f);
        Scanner input = new Scanner(in);
        while (input.hasNextLine()) {
            file.write(input.nextLine());
        }
        input.close();
        file.close();
        Object obj = parser.parse(new FileReader(f));
        JSONObject jsonObj = (JSONObject) obj;
        JSONObject regions = (JSONObject) jsonObj.get("Regions");
        for (String a : worlds) {
            for (String b : types) {
                for (String c : alphabet) {
                    for (int d = 1; d <= alphabet.length; ++d) {
                        String lotId = a + "-" + b + "-" + c + d;
                        String lotIdA = a + "_" + b + "-" + c + d;
                        String lotIdB = a + "-" + b + "_" + c + d;
                        String lotIdC = a + "_" + b + "_" + c + d;
                        JSONObject lot = (JSONObject) regions.get(lotId);
                        JSONObject lotA = (JSONObject) regions.get(lotIdA);
                        JSONObject lotB = (JSONObject) regions.get(lotIdB);
                        JSONObject lotC = (JSONObject) regions.get(lotIdC);
                        ArrayList<Lot> lotInfo = new ArrayList<Lot>();
                        if (lot != null) {
                            lotInfo.add(new Lot((long) lot.get("source_minX"), (long) lot.get("source_maxX"),
                                    (long) lot.get("source_minY"), (long) lot.get("source_maxY"),
                                    (long) lot.get("source_minZ"), (long) lot.get("source_maxZ"),
                                    (String) lot.get("source_file"), lotId));
                            lotInfo.add(new Lot((long) lot.get("dest_minX"), (long) lot.get("dest_maxX"),
                                    (long) lot.get("dest_minY"), (long) lot.get("dest_maxY"),
                                    (long) lot.get("dest_minZ"), (long) lot.get("dest_maxZ"),
                                    (String) lot.get("dest_file"), lotId));
                            lots.add(lotInfo);
                        }
                        if (lotA != null) {
                            lotInfo.add(new Lot((long) lotA.get("source_minX"), (long) lotA.get("source_maxX"),
                                    (long) lotA.get("source_minY"), (long) lotA.get("source_maxY"),
                                    (long) lotA.get("source_minZ"), (long) lotA.get("source_maxZ"),
                                    (String) lotA.get("source_file"), lotIdA));
                            lotInfo.add(new Lot((long) lotA.get("dest_minX"), (long) lotA.get("dest_maxX"),
                                    (long) lotA.get("dest_minY"), (long) lotA.get("dest_maxY"),
                                    (long) lotA.get("dest_minZ"), (long) lotA.get("dest_maxZ"),
                                    (String) lotA.get("dest_file"), lotIdA));
                            lots.add(lotInfo);
                        }
                        if (lotB != null) {
                            lotInfo.add(new Lot((long) lotB.get("source_minX"), (long) lotB.get("source_maxX"),
                                    (long) lotB.get("source_minY"), (long) lotB.get("source_maxY"),
                                    (long) lotB.get("source_minZ"), (long) lotB.get("source_maxZ"),
                                    (String) lotB.get("source_file"), lotIdB));
                            lotInfo.add(new Lot((long) lotB.get("dest_minX"), (long) lotB.get("dest_maxX"),
                                    (long) lotB.get("dest_minY"), (long) lotB.get("dest_maxY"),
                                    (long) lotB.get("dest_minZ"), (long) lotB.get("dest_maxZ"),
                                    (String) lotB.get("dest_file"), lotIdB));
                            lots.add(lotInfo);
                        }
                        if (lotC != null) {
                            lotInfo.add(new Lot((long) lotC.get("source_minX"), (long) lotC.get("source_maxX"),
                                    (long) lotC.get("source_minY"), (long) lotC.get("source_maxY"),
                                    (long) lotC.get("source_minZ"), (long) lotC.get("source_maxZ"),
                                    (String) lotC.get("source_file"), lotIdC));
                            lotInfo.add(new Lot((long) lotC.get("dest_minX"), (long) lotC.get("dest_maxX"),
                                    (long) lotC.get("dest_minY"), (long) lotC.get("dest_maxY"),
                                    (long) lotC.get("dest_minZ"), (long) lotC.get("dest_maxZ"),
                                    (String) lotC.get("dest_file"), lotIdC));
                            lots.add(lotInfo);
                        }
                    }
                }
            }
        }
    } catch (IOException e) {
        System.out.println("FILE ERROR FROM READING JSON");
        e.printStackTrace();
        return null;
    } catch (ParseException e) {
        System.out.println("PARSER ERROR FROM READING JSON");
        e.printStackTrace();
        return null;
    }
    return lots;
}

From source file:Main.java

public static String getHardDiskSN(String drive) {
    String result = "";
    try {/*  w w w  . ja  va 2  s .  c o m*/
        File file = File.createTempFile("realhowto", ".vbs");
        file.deleteOnExit();
        FileWriter fw = new java.io.FileWriter(file);

        String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n"
                + "Set colDrives = objFSO.Drives\n" + "Set objDrive = colDrives.item(\"" + drive + "\")\n"
                + "Wscript.Echo objDrive.SerialNumber"; // see note
        fw.write(vbs);
        fw.close();
        Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
        BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = input.readLine()) != null) {
            result += line;
        }
        input.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result.trim();
}

From source file:com.abiquo.appliancemanager.ApplianceManagerAsserts.java

/**
 * /* w  w w.  jav a2 s  . c  o  m*/
 * 
 * */

protected static void createBundleDiskFile(final String ovfId, final String snapshot) throws Exception {
    EnterpriseRepositoryService er = ErepoFactory.getRepo(String.valueOf(idEnterprise));

    final String ovfpath = TemplateConventions.getRelativePackagePath(ovfId);
    final String diskFilePathRel = er.getDiskFilePath(ovfId);
    // final String diskFilePathRel = diskFilePath.substring(diskFilePath.lastIndexOf('/'));

    final String path = FilenameUtils.concat(FilenameUtils.concat(er.path(), ovfpath),
            (snapshot + "-snapshot-" + diskFilePathRel));

    // "/opt/testvmrepo/1/rs.bcn.abiquo.com/m0n0wall/000snap000-snapshot-m0n0wall-1.3b18-i386-flat.vmdk"

    File f = new File(path);
    f.createNewFile();
    f.deleteOnExit();

    FileWriter fileWriter = new FileWriter(f);
    for (int i = 0; i < 1000; i++) {
        fileWriter.write(i % 1);
    }
    fileWriter.close();
}

From source file:fr.inria.oak.paxquery.xparser.client.XClient.java

private static void printDOTFile(String filePath, String dotString) {
    String filePathDot = filePath;
    String filePathPNG = filePath;
    if (filePathDot.startsWith("file://")) {
        filePathDot = filePathDot.substring("file://".length());
        filePathPNG = filePathPNG.substring("file://".length());
    }/*from   w  ww  . ja  v  a2  s.c  o  m*/
    /*
     * int extensionIndex = filePathDot.lastIndexOf("."); if(extensionIndex > -1) { filePathDot =
     * filePathDot.subSequence(0, extensionIndex) + "-pact.dot"; filePathPNG =
     * filePathPNG.subSequence(0, extensionIndex) + "-pact.png"; } else { filePathDot = filePathDot
     * + "-pact.dot"; filePathPNG = filePathPNG + "-pact.png"; }
     */
    if (filePath.endsWith("/") == true) {
        filePathDot = filePathDot + "xoutput-pact.dot";
        filePathPNG = filePathPNG + "xoutput-pact.png";
    } else {
        filePathDot = filePathDot + "/xoutput-pact.dot";
        filePathPNG = filePathPNG + "/xoutput-pact.png";
    }

    try {
        // print the dot file
        FileWriter writer = new FileWriter(filePathDot, false);
        writer.write(dotString);
        writer.close();
        Runtime r = Runtime.getRuntime();
        String com = new String("dot -Tpng " + filePathDot + " -o " + filePathPNG);
        Process p = r.exec(com);
        p.waitFor();
        // System.out.println("PACT plan drawn.");
    } catch (IOException ioe) {
        System.out.println("Error with pact file: " + ioe.getMessage());
    } catch (InterruptedException ie) {
        System.out.println("Error with pact file: " + ie.getMessage());
    }
}

From source file:com.yahoo.dba.tools.myperfserver.App.java

private static void writePid() {
    if (pid < 0)
        return;//not supported
    try {/*from w  w  w. j  a  v a  2  s .  c o  m*/
        java.io.FileWriter fw = new java.io.FileWriter(PID_FILE);
        fw.write(String.valueOf(pid));
        fw.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}