File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get rid of the leading character

 
Allen Chan
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That works perfect! Thanks so much for the help!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic