File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to get   rid of the leading character Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get   rid of the leading character" Watch "How to get   rid of the leading character" New topic
Author

How to get rid of the leading character

Allen Chan
Ranch Hand

Joined: Jun 07, 2002
Posts: 64
Hi all,
I am trying to read a java class to ftp files but after I write the file, it always has some annoying leading characters (6 to 8 chars), how to fix it. here is the code
****************
import java.net.*;
import java.io.*;
import sun.net.ftp.*;
import sun.net.TelnetInputStream;
class FTP2{
public static void main(String args[]){
try{
URL url = new URL("ftp://username assword@hostname/path/filename");
URLConnection conn = url.openConnection();
// Read from the connection
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
StringBuffer sb= new StringBuffer();
while ((line = in.readLine()) != null){
System.out.println(line);
sb = sb.append(line);
}
in.close();
try{
File fileName= new File("index.html");
ObjectOutputStream output;
output = new ObjectOutputStream(new FileOutputStream(fileName));
output.writeObject(sb.toString());
output.flush();
}catch(IOException e){
}
}catch(Exception e){
}
}
}
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
By using an ObjectOutputStream, you're serializing the String -- yeah, you'll get the serialization headers and all that. Try using a PrintWriter or similar.
- Peter
Allen Chan
Ranch Hand

Joined: Jun 07, 2002
Posts: 64
That works perfect! Thanks so much for the help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get rid of the leading character