Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #11198
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: append() vs. write() |
| Date | 2012-01-10 19:01 -0500 |
| Organization | A noiseless patient Spider |
| 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> |
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