Java Utililty Methods BufferedWriter Write

List of utility methods to do BufferedWriter Write

Description

The list of methods to do BufferedWriter Write are organized into topic(s).

Method

voidwriteFile(String filename, Map map)
Create a new file and write the contents to it
File file = new File(filename);
BufferedWriter bw = null;
Iterator<String> it = map.keySet().iterator();
try {
    file = new File(filename);
    if (!file.exists()) {
        file.createNewFile();
    FileWriter fw = new FileWriter(file.getAbsoluteFile());
    bw = new BufferedWriter(fw);
    while (it.hasNext()) {
        bw.write(map.get(it.next()));
        bw.write("\n");
} catch (IOException e) {
    e.printStackTrace();
} finally {
    try {
        bw.close();
    } catch (IOException e) {
        e.printStackTrace();
voidwriteFile(String line, File file)
write File
writeFile(Arrays.asList(new String[] { line }), file);
voidwritefile(String m, String path)
writefile
try {
    File file = new File(path);
    if (!file.exists()) {
        file.createNewFile();
    FileWriter fileWritter = new FileWriter(file.getName(), true);
    BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
    bufferWritter.write(m);
...
voidwriteFile(String outputLocation, String fileName, List content)
write File
try {
    boolean addLine = true;
    if (!(new File(outputLocation.concat(fileName)).exists())) {
        addLine = false;
    FileWriter fw = new FileWriter(outputLocation.concat(fileName), true);
    BufferedWriter bw = new BufferedWriter(fw);
    int count = 0;
...
voidwriteFile(String p_name, String p_encoding, String p_content)
write File
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(p_name), p_encoding));
out.write(p_content);
out.close();
booleanwriteFileAppend(String filePath, String content)
write File Append
boolean res = true;
BufferedWriter out = null;
try {
    out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath, true), "UTF-8"));
    out.write(content);
} catch (Exception e) {
    res = false;
try {
    out.close();
} catch (IOException e) {
return res;
voidwriteFileContent(File audioFile, short[] data, boolean littleEndian)
write short array as byte file.
try {
    DataOutputStream out = new DataOutputStream(new FileOutputStream(audioFile));
    byte hb, lb;
    if (littleEndian) {
        for (int i = 0; i < data.length; i++) {
            lb = (byte) data[i];
            hb = (byte) (data[i] >> 8);
            out.write(lb);
...
voidwriteFileContents(File file, String contents)
Writes the contents of a string to a file.
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(contents);
writer.close();
voidwriteFilenames(String folderPath, LinkedList listOfPopulationFiles)
write Filenames
FileWriter filesFile = new FileWriter(folderPath + System.getProperty("file.separator") + "files.csv");
BufferedWriter outFiles = new BufferedWriter(filesFile);
outFiles.write("Filenames");
outFiles.newLine();
for (int i = 0; i < listOfPopulationFiles.size(); i++) {
    outFiles.write(listOfPopulationFiles.get(i).getName().substring(0,
            listOfPopulationFiles.get(i).getName().length() - 4));
    outFiles.newLine();
...
voidwriteFileText(File file, String text)
Writes the text data to the specified output file.
OutputStream out = new FileOutputStream(file);
writeLinesCommon(out, text);