Example usage for java.io PrintWriter println

List of usage examples for java.io PrintWriter println

Introduction

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

Prototype

public void println() 

Source Link

Document

Terminates the current line by writing the line separator string.

Usage

From source file:com.frostwire.gui.library.M3UPlaylist.java

/**
 * Call this when you want to save the contents of the playlist.
 * NOTE: only local files can be saved in M3U format, filters out URLs 
 * that are not part of the local filesystem
 * @exception IOException Throw when save failed.
 * @exception IOException Throw when save failed.
 *//*from   w  ww  .j av a 2  s  .c om*/
public static void save(String fileName, List<File> files) throws IOException {
    File playListFile = new File(fileName);
    // if all songs are new, just get rid of the old file.  this may
    // happen if a delete was done....
    if (files.size() == 0) {
        //            if (playListFile.exists()) {
        //                playListFile.delete();
        //            }
        return;
    }

    PrintWriter m3uFile = null;
    try {
        m3uFile = new PrintWriter(new FileWriter(playListFile.getCanonicalPath(), false));

        m3uFile.write(M3U_HEADER);
        m3uFile.println();

        for (File currFile : files) {
            // only save files that are local to the file system
            if (currFile.isFile()) {
                File locFile;
                locFile = new File(currFile.toURI());

                // first line of song description...
                m3uFile.write(SONG_DELIM);
                m3uFile.write(SEC_DELIM);
                // try to write out seconds info....
                //if( currFile.getProperty(PlayListItem.LENGTH) != null )
                //    m3uFile.write("" + currFile.getProperty(PlayListItem.LENGTH) + ",");
                //else
                m3uFile.write("" + -1 + ",");
                m3uFile.write(currFile.getName());
                m3uFile.println();
                // canonical path follows...
                m3uFile.write(locFile.getCanonicalPath());
                m3uFile.println();
            }
        }
    } finally {
        IOUtils.closeQuietly(m3uFile);
    }
}

From source file:Main.java

public static int outputNode(Node outputNode, PrintWriter outputWriter, int curPos) {
    NodeList nodes = outputNode.getChildNodes();
    int curNodeNum;
    if (outputNode.getNodeType() == Node.TEXT_NODE) {
        outputWriter.print(outputNode.getNodeValue());
    } else {//from w w w. j a  va 2 s  . co m
        if (outputNode.getNodeName().equals("p")) {
            outputWriter.println();
        }

        for (curNodeNum = 0; curNodeNum < nodes.getLength(); curNodeNum++) {
            Node curNode = nodes.item(curNodeNum);
            curPos = outputNode(curNode, outputWriter, curPos);
            //System.out.println(curNode.getNodeName());
            //System.out.println(curNode.getNodeValue());
        }

    }
    return (curPos);
}

From source file:ca.cutterslade.match.scheduler.Main.java

private static String summary(final Scheduler scheduler) {
    final StringWriter w = new StringWriter();
    final PrintWriter p = new PrintWriter(w);
    final String columnFormat = " %15s";
    p.printf(columnFormat, "Day");
    p.printf(columnFormat, "Time");
    for (final Court c : scheduler.getCourts()) {
        p.printf(columnFormat, c.getGym().getName() + '-' + c.getName());
    }/*w ww  .  ja v a 2  s.c  o m*/
    p.println();
    for (final Day d : scheduler.getDays())
        for (final Time t : scheduler.getTimes()) {
            p.printf(columnFormat, d.getName());
            p.printf(columnFormat, t.getName());
            for (final Court c : scheduler.getCourts()) {
                final Match m = scheduler.getMatch(d, t, c);
                p.printf(columnFormat, teamsString(m));
            }
            p.println();
        }
    p.close();
    return w.toString();
}

From source file:Main.java

public static int outputNode(Node outputNode, PrintWriter outputWriter, int curPos) {
    NodeList nodes = outputNode.getChildNodes();
    int curNodeNum;
    if (outputNode.getNodeType() == Node.TEXT_NODE) {
        outputWriter.print(outputNode.getNodeValue());
    } else {/*w  w w.j a  v a  2s. c om*/
        if (outputNode.getNodeName().equals("p")) {
            outputWriter.println();
        }

        for (curNodeNum = 0; curNodeNum < nodes.getLength(); curNodeNum++) {
            Node curNode = nodes.item(curNodeNum);
            curPos = outputNode(curNode, outputWriter, curPos);
        }

    }
    return (curPos);
}

From source file:com.ms.commons.test.tool.GenerateTestCase.java

private static void writeAddedMembersToTestFile(File testFile, List<MethodDeclaration> addedMethods,
        StringBuilder testUnitReadEncoding) {
    try {//from  www  . j  av  a  2s  . c o  m
        String code = readCodeFromFile(testFile, new StringBuilder());

        String codePart1 = code.substring(0, code.lastIndexOf('}'));
        String codePart2 = code.substring(code.lastIndexOf('}'));

        StringWriter sw = new StringWriter();
        PrintWriter newMethodsCode = new PrintWriter(sw);

        for (MethodDeclaration method : addedMethods) {
            newMethodsCode.println();
            String me = method.toString();
            BufferedReader br = new BufferedReader(new StringReader(me));
            for (String l; (l = br.readLine()) != null;) {
                newMethodsCode.println("    " + l);
            }
        }
        newMethodsCode.flush();

        String newCode = codePart1 + sw + codePart2;

        // check if have syntax error
        JavaParser.parse(convertStringToInputstream(newCode, "UTF-8"), "UTF-8");

        FileUtils.writeStringToFile(testFile, newCode, testUnitReadEncoding.toString());
    } catch (Exception e) {
        throw ExceptionUtil.wrapToRuntimeException(e);
    }
}

From source file:mx.unam.ecologia.gye.coalescence.app.CreateMicsatInput.java

protected static final void writeMicsat(List leaves, String fname) {
    try {// www. ja va2s . c om

        FileOutputStream fout = new FileOutputStream(fname);
        PrintWriter pw = new PrintWriter(fout);
        for (int i = 0; i < leaves.size(); i++) {
            UniParentalGene upgene = (UniParentalGene) leaves.get(i);
            CompoundSequence h = upgene.getCompoundSequence();
            int numloc = h.getSequenceCount();
            for (int n = 0; n < numloc; n++) {
                Sequence s = h.get(n);
                pw.print(s.getSize());
                pw.print(" ");
            }
            pw.println();
        }
        pw.flush();
        pw.close();
        fout.close();
    } catch (IOException ex) {
        log.error("writeMicsat()", ex);
    }

}

From source file:IO.java

public static void writeData(int[][] data, int nData, int nDim, String filepath) {
    File file = new File(filepath);
    PrintWriter writer;

    try {//from  www  .  j ava 2s.c o  m

        writer = new PrintWriter(file);
        for (int i = 0; i < nData; i++) {
            for (int j = 0; j < nDim; j++) {
                if (j == nDim - 1) {
                    writer.print(data[i][j]);
                } else {
                    writer.print(data[i][j] + ",");
                }
            }
            writer.println();
        }
        writer.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:IO.java

public static void writeData(double[][] data, int nData, int nDim, String filepath) {
    File file = new File(filepath);
    PrintWriter writer;

    try {//from w  w  w  .j a  v  a  2 s . co  m

        writer = new PrintWriter(file);
        for (int i = 0; i < nData; i++) {
            for (int j = 0; j < nDim; j++) {
                if (j == nDim - 1) {
                    writer.print(data[i][j]);
                } else {
                    writer.print(data[i][j] + ",");
                }

            }
            writer.println();
        }
        writer.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:duty_scheduler.Scheduler.java

/**
 * Prints analytics data to a space separated file called analytics.txt
 *///from  ww  w.ja va  2 s. c o  m
private static void printAnalytics() {
    String analyticsFile = "analytics.txt";
    PrintWriter analysisOut = null;
    try {
        analysisOut = new PrintWriter(analyticsFile);
        for (double[] generationData : analytics) {
            for (double dataPoint : generationData) {
                analysisOut.print(String.format("%.3f ", dataPoint));
            }
            analysisOut.println();
        }
    } catch (IOException e) {
        ErrorChecker.printExceptionToLog(e);
    } finally {
        analysisOut.close();
    }
}

From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtil.java

private static void writeSources(PrintWriter out, Set<Source> sources) {
    out.print("!Sample_source_name=");
    String del = "";

    for (final Source source : sources) {
        out.print(del);//  w w  w .  j  a v a 2 s  .co  m
        out.print(source.getName());
        del = "; ";
    }
    out.println();
}