"johnmmcparland" <johnmmcparland@googlemail.com> je napisao u poruci
interesnoj grupi:1156769038.065630.258870@i3g2000cwc.googlegroups.com...
>> How can I force my application to memorize the column width, so that I
>> don't
[quoted text clipped - 12 lines]
>
> hope this helps
I found the next example of saving column properties:
columnNames=new String[table.getColumnCount()];
for (int i=0;i<columnNames.length;i=i+1)
{
columnNames[
i ]=table.getColumnModel().getColumn(i).getHeaderValue().toString();
}
---
data=new String[columnNames.length*table.getRowCount()];
j=0;
for (int i=0;i< table.getRowCount();i=i+1)
{
data[j]=table.getValueAt(i,0).toString();
data[j+1]=table.getValueAt(i,1).toString();
data[j+2]=table.getValueAt(i,2).toString();
j=j+3;//for 3 Cols
}
---
File file = new File("myTable.CSV");
String fileData;
if (file != null)
{
try
{
BufferedWriter bufferedWriter = new BufferedWriter(new
FileWriter(file,true));
PrintWriter fileWriter = new PrintWriter(bufferedWriter);
System.out.println("Column Headers ");
for(int j=0; j < table.getColumnCount(); ++j)
{
fileData=columnNames[ i ];
fileWriter.print(fileData+",");
}
System.out.println("Done.... ");
fileWriter.println("");
System.out.println("Exporting Data ");
for(int i=0; i<table.getRowCount(); ++i)
{
for(int j=0; j < table.getColumnCount(); ++j)
{
fileData = table.getValueAt(i,j).toString();
fileWriter.print(fileData+",");
}
fileWriter.println("");
}
fileWriter.close();
System.out.println("Done.... ");
But I don't understand what is .csv, why that extension and how to read it
?
Michael Rauscher - 29 Aug 2006 06:06 GMT
Dado schrieb:
> I found the next example of saving column properties:
It's an example of saving table data.
> But I don't understand what is .csv, why that extension and how to read it
CSV is an abbreviation for Comma Separated Values or Character Separated
Values. A file in CSV format is a text file which usually contains
records which field-values are separated by a special character e. g. a
comma. The output of the code you quoted in your last post could look
like this:
Name,First Name,Sex
Smith,Trevor,Male
Miller,Marlene,Female
As long there is no really good reason for storing properties in CSV
files, don't do it.
Using java.util.prefs.Preferences your configuration data is stored in
an implementation-depended backing store. E. g. in Windows it's stored
in the registry.
If you don't want an implementation-dependend backing store (because you
want the preferences be editable by an ordinary text editor for example)
you can use java.util.Properties and store/load it to/from a properties
file.
Bye
Michael