Example usage for java.io BufferedWriter write

List of usage examples for java.io BufferedWriter write

Introduction

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

Prototype

public void write(int c) throws IOException 

Source Link

Document

Writes a single character.

Usage

From source file:com.microsoft.alm.plugin.idea.common.setup.WindowsStartup.java

/**
 * Create VB script to run KeyCreator application as elevated
 *
 * @param newCmd//from www  . j  a  v a2 s .  c om
 * @return script file
 * @throws IOException
 */
protected static File createRegeditFile(final File newCmd) throws IOException {
    final File script = File.createTempFile("CreateKeys", ".reg");
    final FileWriter fileWriter = new FileWriter(script);
    final BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
    try {
        bufferedWriter.write("Windows Registry Editor Version 5.00\r\n\r\n"
                + "[-HKEY_CLASSES_ROOT\\vsoi]\r\n\r\n" + "[HKEY_CLASSES_ROOT\\vsoi]\r\n"
                + "\"URL Protocol\"=\"\"\r\n\r\n" + "[HKEY_CLASSES_ROOT\\vsoi\\Shell\\Open\\Command]\r\n"
                + "\"\"=\"" + newCmd.getPath().replace("\\", "\\\\") + " \\\"%1\\\" \"");
    } finally {
        if (bufferedWriter != null) {
            bufferedWriter.close();
        }
    }
    return script;
}

From source file:Main.java

public static void writeFile(String filename, String text) throws Exception {
    File f = new File(filename);
    if (!f.exists())
        f.createNewFile();//from  ww  w .j a v a2 s. com
    else {
        f.delete();
        f.createNewFile();
    }
    BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "utf-8"));

    // new BufferedWriter(new FileWriter(filename,
    // false),"utf-8");
    output.write(text);

    output.flush();
    output.close();
}

From source file:JMeterProcessing.JMeterPropertiesGenerator.java

private static void printProperties(BufferedWriter writer, Map<String, Long> idValuesMap) throws IOException {
    writer.newLine();/* w  w  w. j a  v a 2  s  .c o m*/

    writer.write("# Jmeter server\n");
    writer.write("full.depth.server=" + _SERVER + "\n");
    writer.write("full.depth.server.port=" + _PORT + "\n");
    writer.write("full.depth.protocol=" + _PROTOCOL + "\n");
    writer.newLine();

    writer.write("# Testray Object Ids\n");

    for (Map.Entry<String, Long> entry : idValuesMap.entrySet()) {
        writer.write("full.depth." + entry.getKey() + "=" + entry.getValue() + "\n");
    }

    writer.newLine();
    writer.write("# Login Info\n");
    writer.write("full.depth.user=" + _USERNAME + "\n");
    writer.write("full.depth.password=" + _PASSWORD);
}

From source file:net.idlesoft.android.apps.github.utils.GravatarCache.java

/**
 * Returns a Gravatar ID associated with the provided name
 * // ww  w . j  a v a 2  s .co  m
 * @param name
 * @return the gravatar ID associated with the name
 */
public static String getGravatarID(final String name) {
    String id = "";
    try {
        final File gravatars = ensure_directory(ROOT_DIR);
        final File gravatar_id = new File(gravatars, name + ".id");

        if (gravatar_id.isFile()) {
            final FileReader fr = new FileReader(gravatar_id);
            final BufferedReader in = new BufferedReader(fr);
            id = in.readLine();
            in.close();
        } else {
            id = getGravatarIdFromGithub(name);
            if (!id.equals("")) {
                final FileWriter fw = new FileWriter(gravatar_id);
                final BufferedWriter bw = new BufferedWriter(fw);
                bw.write(id);
                bw.flush();
                bw.close();
            }
        }
    } catch (final IOException e) {
        e.printStackTrace();
    }
    return id;
}

From source file:Main.java

public static void writeFile(String filepath, InputStream is) throws IOException {
    File file = new File(filepath);
    BufferedWriter bw = new BufferedWriter(new FileWriter(file));

    BufferedReader br = new BufferedReader(new InputStreamReader(is));

    String line;// w  ww  . j a v a2s .  com
    while ((line = br.readLine()) != null) {
        bw.write(line + "\n");
    }

    bw.close();
    br.close();
}

From source file:co.foxdev.foxbot.utils.Utils.java

public static boolean addCustomCommand(String channel, String command, String text) {
    String filePath = "data/custcmds/" + channel.substring(1);
    File path = new File(filePath);

    try {/*w w w .j a v  a2 s.co  m*/
        if (!path.exists() && !path.mkdirs()) {
            foxbot.getLogger().warn("Error occurred while creating custom command folders!");
        }

        File file = new File(filePath + "/" + command);

        if (file.exists() && !file.delete()) {
            foxbot.getLogger().warn(
                    String.format("Error occurred while deleting command '%s' for %s!", command, channel));
        }

        if (text.isEmpty() || text.equalsIgnoreCase("delete")) {
            if (file.delete()) {
                foxbot.getLogger().warn(String.format("Command '%s' deleted for %s!", command, channel));
            }
            return false;
        }

        FileWriter fw = new FileWriter(filePath + "/" + command);
        BufferedWriter bw = new BufferedWriter(fw);

        bw.write(text);
        bw.flush();
        bw.close();
        fw.flush();
        fw.close();
        foxbot.getLogger()
                .warn(String.format("Command '%s' set for %s at %s", command, channel, file.getAbsolutePath()));
    } catch (IOException ex) {
        foxbot.getLogger().error("Error occurred while adding custom command", ex);
    }
    return true;
}

From source file:Main.java

public static boolean createFile(String name) {
    File outfile = new File(name);
    BufferedWriter writer = null;
    if (!outfile.isFile()) {
        try {/*from  w  ww. ja v  a 2 s  .co m*/
            outfile.createNewFile();
            writer = new BufferedWriter(new FileWriter(outfile));
            writer.write(
                    "#_*_ coding: iso8859_1\n# Script API\n\nfrom com.android.python import AndroidDriver\n\n");
            writer.flush();
            return true;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return false;
}

From source file:Main.java

public static void writeFile(String content, String path) {
    FileOutputStream fos = null;/*from w  w w . j  av a 2 s .  com*/
    BufferedWriter bw = null;
    try {
        File file = new File(path);
        fos = new FileOutputStream(file);
        bw = new BufferedWriter(new OutputStreamWriter(fos, "GB2312"));
        bw.write(content);
    } catch (FileNotFoundException fnfe) {
        fnfe.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } finally {
        try {
            if (bw != null)
                bw.close();
            if (fos != null)
                fos.close();
        } catch (IOException ie) {
        }
    }
}

From source file:org.esupportail.twitter.services.OAuthTwitterApplicationOnlyService.java

private static boolean writeRequest(HttpURLConnection connection, String textBody) {
    try {/*  w  w  w.j  a v  a 2 s  .c  o  m*/
        BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
        wr.write(textBody);
        wr.flush();
        wr.close();

        return true;
    } catch (IOException e) {
        return false;
    }
}

From source file:com.dragovorn.dragonbot.api.bot.file.FileManager.java

public static void setDirectory(String directory) {
    File file = new File(directory, "Dragon Bot");

    if (FileManager.directory.exists() && !file.exists()) {
        if (file.mkdirs()) {
            try {
                FileUtils.copyDirectory(FileManager.directory, file);
            } catch (IOException exception) {
                exception.printStackTrace();
            }/*w ww . j a  v  a  2 s . com*/
        } else {
            throw new RuntimeException("Unable to create file: " + file.getName()); // FIXME: 11/23/16 make custom exception
        }

        try {
            FileUtils.deleteDirectory(FileManager.directory);
        } catch (IOException exception) {
            exception.printStackTrace();
        }
    }

    FileManager.directory = file;

    File path = new File(FileManager.dir, "path");

    try {
        FileWriter fileWriter = new FileWriter(path);

        BufferedWriter writer = new BufferedWriter(fileWriter);

        writer.write(directory);

        writer.close();
        fileWriter.close();
    } catch (IOException exception) {
        exception.printStackTrace();
    }

    reloadFiles();
}