Example usage for java.io FileWriter FileWriter

List of usage examples for java.io FileWriter FileWriter

Introduction

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

Prototype

public FileWriter(File file, Charset charset) throws IOException 

Source Link

Document

Constructs a FileWriter given the File to write and java.nio.charset.Charset charset .

Usage

From source file:co.cask.cdap.filetailer.tailer.TailerLogUtils.java

public static void writeLineToFile(String filePath, String line) throws IOException {
    Writer writer = new FileWriter(filePath, true);
    writer.write(line + "\n");
    writer.flush();//from w  w  w.  j  av a 2s.  c o  m
    writer.close();
}

From source file:model.SQLiteModel.java

public static void writeLineToLog(String line) {
    try {/*w ww . j  a v  a2 s  .  com*/
        writer = new FileWriter(logPath, true);
        print_line = new PrintWriter(writer);
        print_line.println(line);
        writer.close();
        print_line.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:de.bley.word.filewriter.WriterFile.java

/**
 * Schreibt Daten in eine Textdatei.//from  www  .j  av a2  s .  co  m
 *
 * @param filepath Pfad der zulesenden Datei.
 * @param text String, welcher in die Datei geschrieben werden soll.
 * @param flag Boolean, ob Text angehangen oder ueberschrieben werden soll.
 *
 */
@Override
public void writeInFile(String filepath, final String text, final boolean flag) {

    try {
        final FileWriter writer = new FileWriter(filepath, flag);
        writer.write(text + System.getProperty("line.separator"));
        writer.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:net.decix.jatlasx.csv.CsvWriter.java

public CsvWriter(String filename, Object[] fileHeader) throws IOException {
    this.filename = filename;
    boolean fileExists = new File(filename).exists();
    fileWriter = new FileWriter(filename, true);
    printer = new CSVPrinter(fileWriter, csvFileFormat);

    // only write header if file does not exist yet
    if (!fileExists) {
        printer.printRecord(fileHeader);
    }/*from   www .  ja va  2  s . c o m*/

}

From source file:com.kappaware.logtrawler.output.flow.FileJsonOutputFlow.java

public FileJsonOutputFlow(String fileName, boolean outputArray) throws IOException {
    super(outputArray);
    out = new PrintWriter(new BufferedWriter(new FileWriter(fileName, true)));
    log.info(String.format("Json events will be stored in to '%s'", fileName));
}

From source file:gumga.framework.application.GumgaLoggerService.java

public void logToFile(String msg, int level) {
    try {/*  w  ww  .j  a  v  a  2s  .c o  m*/
        String line = createLogLine(msg, level);
        File folder = new File(gumgaValues.getLogDir());
        folder.mkdirs();
        File log = new File(folder, "gumgalog.txt");
        FileWriter fw = new FileWriter(log, true);
        fw.write(line);
        fw.close();
    } catch (IOException ex) {
        log.error("Problema ao loggar no arquivo", ex);
    }
}

From source file:cfd.backupper.state.StartupConfig.java

public static void putSetting(String key, List l) {

    //l needs to be toString(), otherwise there are no doublequotes in JSON.
    List stringedList = (List) l.stream().map(elem -> elem.toString()).collect(Collectors.toList());
    if (jo.containsKey(key)) {
        jo.replace(key, stringedList);/*from w w  w  .j  a v  a 2 s  .  c  om*/
    } else {
        jo.put(key, stringedList);
    }
    try {
        FileWriter fw = new FileWriter(confFile, false);
        fw.append(jo.toJSONString());
        fw.flush();
        fw.close();
    } catch (IOException ex) {
        Logger.getLogger(StartupConfig.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.kappaware.logtrawler.output.flow.FileDataOutputFlow.java

public FileDataOutputFlow(String fileName) throws IOException {
    out = new PrintWriter(new BufferedWriter(new FileWriter(fileName, true)));
    log.info(String.format("Data events will be stored in to '%s'", fileName));
}

From source file:files.FileUtils.java

public static boolean WriteFile(String pathFileText, String fileContent) {
    try {/*from w  w  w . j ava  2s . c om*/
        File file = new File(pathFileText);

        //if file doesnt exists, then create it
        if (!file.exists()) {
            file.createNewFile();
        }

        //Collecting Data
        if (!CommonUtils.IsNullOrEmpty(fileContent)) {
            //true = append file
            FileWriter fileWritter = new FileWriter(file.getPath(), false);
            try (BufferedWriter bufferWritter = new BufferedWriter(fileWritter)) {
                bufferWritter.write(fileContent);
            }
            return true;
        }
    } catch (IOException ex) {
        return false;
    }
    return false;
}

From source file:io.gumga.application.GumgaLoggerService.java

/**
 * Adiciona uma mensagem no gumgalog.txt
 * @param msg mensagem a ser adicionada no arquivo
 * @param level index da execption do StrackTrace
 */// www  . j a v a2s.  co  m
public void logToFile(String msg, int level) {
    try {
        String line = createLogLine(msg, level);
        File folder = new File(gumgaValues.getLogDir());
        folder.mkdirs();
        File log = new File(folder, "gumgalog.txt");
        FileWriter fw = new FileWriter(log, true);
        fw.write(line);
        fw.close();
    } catch (IOException ex) {
        log.error("Problema ao loggar no arquivo", ex);
    }
}