How do i prevent [] from appearing in output when reading vector data?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Barry_Dogger
Posted On:   Thursday, April 4, 2002 01:47 AM

Here's the code: public void saveFile(File file) { try { PrintWriter out = new PrintWriter( new FileOutputStream(file),true); Vector line = null; int i =0; while (i < data.size()) { line = (Vector)data.get(i); System.out.println("What is line ? " +line); i++; System.out.println("Before write "); out.println(line); System.out.println("After write "); } out.close(); } Here is the result of the line:System.out.println("What is line ? " +line);    More>>

Here's the code:


public void saveFile(File file)

{

try

{

PrintWriter out = new PrintWriter(

new FileOutputStream(file),true);

Vector line = null;

int i =0;
while (i < data.size())

{

line = (Vector)data.get(i);

System.out.println("What is line ? " +line);

i++;

System.out.println("Before write ");

out.println(line);

System.out.println("After write ");

}

out.close();

}


Here is the result of the line:System.out.println("What is line ? " +line);



[Name , adres , Zip code, City , Phone , email]



I do not want to write the [ ] to my output file, because they appear in my table when i read the file again.



Thanks in advance.



regards,


Barry

   <<Less

Re: How do i prevent [] from appearing in output when reading vector data?

Posted By:   Jonathan_Downey  
Posted On:   Friday, April 5, 2002 05:14 AM


String lineStr = line.toString();
out.println(lineStr.substring(1, lineStr.length()-1 ));

When you output a vector like you are doing above, you are actually calling the Vector.toString method, which returns a String. So then you can all any String methods on lineStr.

Jonathan

About | Sitemap | Contact