Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #11198
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Jeff Higgins <jeff@invalid.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: append() vs. write() |
| Date | Tue, 10 Jan 2012 19:01:50 -0500 |
| Organization | A noiseless patient Spider |
| Lines | 69 |
| Message-ID | <jeij4b$fkq$1@dont-email.me> (permalink) |
| References | <3d2746a6-f57c-4fa1-b547-dfddc23bb6b6@n30g2000yqd.googlegroups.com> <jeib9l$shf$1@dont-email.me> <jeicso$7pr$1@dont-email.me> <jeihiq$8dr$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Tue, 10 Jan 2012 23:54:51 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="qwFw1g9RsQ6TkML5yezG9A"; logging-data="16026"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8+4fcnlkPvuDUXXI02ZtG5R1Eg9C+k5s=" |
| User-Agent | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20111110 Icedove/3.0.11 |
| In-Reply-To | <jeihiq$8dr$1@dont-email.me> |
| Cancel-Lock | sha1:d7TnyBOqgkG67cnYVOwpCJGk190= |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11198 |
Show key headers only | View raw
On 01/10/2012 06:35 PM, Jeff Higgins wrote:
> On 01/10/2012 05:15 PM, Jeff Higgins wrote:
>> On 01/10/2012 04:48 PM, Jeff Higgins wrote:
>>> On 01/10/2012 11:17 AM, Benjamin Trendelkamp-Schroer wrote:
>>>> Hi,
>>>>
>>>> I want to write a method that can write possibly large matrices of
>>>> floating point numbers in scientific notation to human readable ascii
>>>> files. I want to be able to specify the formatting of the floating
>>>> point numbers usins format strings like "%1.8e" or "%2.5f".
>>>>
>> Oops! java.utilFormatter Duh. Sorry, please ignore previous post.
>
> Well,maybe not all is lost.
> PrintWriter does have a printf( String format, Object... args).
> So I guess you can lose the DecimalFormat for the printf.
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Collection;
public class Scratch {
public static void main(String[] args) throws IOException {
PrintWriter writer = new PrintWriter(
new BufferedWriter(
new FileWriter(args[0])));
String tableHeader, tableFooter,
rowHeader, rowFooter, columnSeparator;
// not intended to compile
Matrix matrix;
MatrixRow row;
writer.print(tableHeader);
while (matrix.hasRows()) {
row = matrix.nextRow();
writer.print(rowHeader);
while (row.hasNextCell()) {
printFormattedCellValue(
writer,row.nextCell().doubleValue(),row.rowIndex,row.columnIndex);
writer.print(columnSeparator);
}
writer.append(rowFooter);
}
writer.append(tableFooter);
}
}
/* probably in your Matrix class
void printFormattedCellValue(
PrintWriter writer, double value, int rowIndex, int columnIndex) {
// apply a format depending upon rowIndex and columnIndex
String format;
Object[] args;
writer.printf(format,value,args[0]...);
}
*/
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
append() vs. write() Benjamin Trendelkamp-Schroer <benjamin.trendelkampschroer@googlemail.com> - 2012-01-10 08:17 -0800
Re: append() vs. write() Jeff Higgins <jeff@invalid.invalid> - 2012-01-10 13:14 -0500
Re: append() vs. write() markspace <-@.> - 2012-01-10 13:30 -0800
Re: append() vs. write() Jeff Higgins <jeff@invalid.invalid> - 2012-01-10 16:48 -0500
Re: append() vs. write() Jeff Higgins <jeff@invalid.invalid> - 2012-01-10 17:15 -0500
Re: append() vs. write() Jeff Higgins <jeff@invalid.invalid> - 2012-01-10 18:35 -0500
Re: append() vs. write() Jeff Higgins <jeff@invalid.invalid> - 2012-01-10 19:01 -0500
Re: append() vs. write() Lew <noone@lewscanon.com> - 2012-01-10 18:06 -0800
csiph-web