Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you read the file line by line using a <a href="http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html" rel="nofollow"><code>BufferedReader</code></a> (it offers a method <a href="http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html#readLine%28%29" rel="nofollow"><code>readLine()</code></a>), you can then write the output to another file using a <a href="http://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html" rel="nofollow"><code>PrintWriter</code></a> and first you write the <code>$</code> character using <a href="http://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html#print%28char%29" rel="nofollow"><code>print()</code></a> and then the line you read from the <code>BufferedReader</code> using <a href="http://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html#println%28java.lang.String%29" rel="nofollow"><code>println()</code></a>.</p> <p>Note that concatenating strings using the + operator in Java is very slow.</p> <p>Something like this should work (slightly simpler than the sample you found):</p> <pre><code>try (BufferedReader input = new BufferedReader(new FileReader(new File("inputfile.txt"))); PrintWriter output = new PrintWriter(new File("outputfile.txt"))) { String line; while (input.ready() &amp;&amp; ((line = input.readLine()) != null)) { output.print("$"); output.println(line); } } catch (Exception ex) { ex.printStackTrace(); } </code></pre> <p>The above example uses the new Java 7 <a href="http://java.dzone.com/articles/java-7-new-try-resources" rel="nofollow">autoclose feature</a> in the <code>try</code> block to close the streams after the process finishes.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload