Example usage for org.apache.commons.io FileUtils writeLines

List of usage examples for org.apache.commons.io FileUtils writeLines

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils writeLines.

Prototype

public static void writeLines(File file, Collection lines, String lineEnding) throws IOException 

Source Link

Document

Writes the toString() value of each item in a collection to the specified File line by line.

Usage

From source file:com.mvdb.scratch.HadoopClientTest.java

private static void createDataFile(String dataFileName) {
    int numOfLines = 20;
    String baseStr = "....Test...";
    List<String> lines = new ArrayList<String>();
    for (int i = 0; i < numOfLines; i++)
        lines.add(i + baseStr + UUID.randomUUID());

    File dataFile = new File(dataFileName);
    try {//  ww  w . java  2s  .  co m
        FileUtils.writeLines(dataFile, lines, true);
        Thread.sleep(2000);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:com.ctt.persistance.StorageFile.java

public static void saveTransaction(Transaction t) throws IOException {
    try {//ww  w .ja  v  a2  s  .  c om

        List<String> list = new ArrayList<String>();
        list.add(t.transactionString());

        String name_file = Main.prop.getProperty("path_transactions") + "transactions_" + t.getCard_number()
                + ".csv";

        File f = new File(name_file);
        if (!f.exists()) {
            f.createNewFile();
        }

        System.out.println("Guardar Transacciones");

        FileUtils.writeLines(new File(name_file), list, true);
    } catch (Exception e) {
        Main.appendLog("Error: SAVE TRANSACTION: " + e.getMessage());
    }
}

From source file:alilibs.AliFile.java

public static void writenew(String url, List<String> values) {
    try {//from w  ww.j  a v a  2  s.c  om
        FileUtils.writeLines(new File(url), values, false);

    } catch (IOException ex) {
    }
}

From source file:de.tudarmstadt.ukp.csniper.resbuild.stuff.InclusionsCreator.java

@Test
public void createInclusionsFile() throws IOException {
    List<String> all = read(BASE_0, "xml");
    //      all.removeAll(cut(read(BASE, "csv"), read(BASE, "xz")));
    all.removeAll(cut(read(BASE, "csv"), stripPlusXml(read("serialized.txt"))));
    //      all.removeAll(read(BASE, "csv"));
    FileUtils.writeLines(new File(BASE, "inclusions.txt"), "UTF-8", all);
    //      all.removeAll(read(BASE, "xz"));
    //      all.removeAll(read(BASE, "csv"));
    IOUtils.writeLines(all, "\n", System.out, "UTF-8");
}

From source file:com.quancheng.plugin.common.AbstractPrint.java

public void print() {
    String fileName = fileRootPath + "/" + StringUtils.replace(sourcePackageName.toLowerCase(), ".", "/") + "/"
            + className + ".java";
    File javaFile = new File(fileName);
    List<String> fileData = collectFileData();
    if (fileData != null) {
        try {//from  www.  java  2s .c om
            FileUtils.writeLines(javaFile, "UTF-8", fileData);
        } catch (IOException e) {
            throw new IllegalArgumentException("can not write file to" + fileName, e);
        }
    }
}

From source file:com.thoughtworks.go.agent.bootstrapper.LauncherTempFileHandler.java

synchronized static void writeToFile(final List<String> rows, final boolean append) {
    try {/* w  ww  .  ja va2  s. c om*/
        FileUtils.writeLines(new File(LAUNCHER_TMP_FILE_LIST), rows, append);
    } catch (IOException e) {
        LOG.error("Could not update temp files list", e);
    }
}

From source file:edu.cuhk.hccl.IDConverter.java

private static void processFile(File inFile, File outFile) throws IOException {
    List<String> lines = FileUtils.readLines(inFile, "UTF-8");
    List<String> buffer = new ArrayList<String>();

    for (String line : lines) {
        String[] cols = line.split("\t");

        cols[0] = String.valueOf(mapping.getUserID(cols[0]));
        cols[1] = String.valueOf(mapping.getItemID(cols[1]));

        buffer.add(StringUtils.join(cols, '\t'));
    }/*from  w  w  w.jav a 2 s  .c o m*/

    Collections.sort(buffer);
    FileUtils.writeLines(outFile, buffer, false);

    System.out.printf("ID Converting finished for file: %s.\n", inFile.getAbsolutePath());
}

From source file:com.l2jfree.tools.NewLineChecker.java

private static void parse(File f) throws IOException {
    if (f.isDirectory()) {
        for (File f2 : f.listFiles(FILTER))
            parse(f2);//www  .  java2  s.c o  m
        return;
    }

    final String input = FileUtils.readFileToString(f);
    final List<String> inputLines = FileUtils.readLines(f);

    final int r = StringUtils.countMatches(input, "\r");
    final int n = StringUtils.countMatches(input, "\n");
    final int rn = StringUtils.countMatches(input, "\r\n");

    final char lastChar = input.charAt(input.length() - 1);
    boolean missingNewline = false;

    if (lastChar != '\r' && lastChar != '\n') {
        System.out.println("--- " + f.getCanonicalPath());
        System.out.println(lastChar);

        MISSING_NEWLINE++;

        missingNewline = true;
    }

    // fully "\r\n"
    if (r == n && r == rn && n == rn) {
        RN++;
        if (missingNewline)
            FileUtils.writeLines(f, inputLines, "\r\n");
        return;
    }

    // fully "\n"
    if (r == 0 && rn == 0) {
        N++;
        System.out.println("n " + f.getName());
        if (missingNewline)
            FileUtils.writeLines(f, inputLines, "\n");
        return;
    }

    System.out.println("--- " + f.getCanonicalPath());
    System.out.println("r: " + r);
    System.out.println("n: " + n);
    System.out.println("rn: " + rn);

    FileUtils.writeLines(f, inputLines, f.getName().endsWith(".sh") ? "\n" : "\r\n");

    // fully "\r"
    if (n == 0 && rn == 0) {
        R++;
        return;
    }

    // mixed
    MIXED++;
}

From source file:com.utdallas.s3lab.smvhunter.monkey.LogcatMonitor.java

@Override
public void run() {

    //monitor the logcat for analysis
    Process pr = null;//from w ww  .  j  ava 2  s  .  c  o m
    try {
        pr = NetworkMonitor
                .execCommand(String.format(LOGCAT, WindowUpdate.adbLocation, device.getSerialNumber()));
        BufferedReader br = new BufferedReader(new InputStreamReader(pr.getInputStream()));
        String s = null;

        ArrayList<String> tmpList = new ArrayList<String>();
        while ((s = br.readLine()) != null) {
            String forPrinting = NetworkMonitor.getStringforPrinting(device.getSerialNumber(),
                    System.currentTimeMillis(), s);
            tmpList.add(forPrinting);

            //write every 100 lines
            if (tmpList.size() == 100) {
                FileUtils.writeLines(new File(MonkeyMe.logCatLocation), tmpList, true);
                tmpList.clear();
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (pr != null) {
            pr.destroy();
        }
    }
}

From source file:com.bluexml.tools.miscellaneous.Translate.java

public static void prapareFileToTranslate(File input, File outDir) throws IOException {
    // create file that contains only text
    File output = new File(outDir, input.getName() + ".txt");

    TreeMap<String, String> props = loadProperties(input);
    Collection<String> lines = props.values();

    FileUtils.writeLines(output, "UTF-8", lines);
}