• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to get rid of the leading character

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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){
}
}
}
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That works perfect! Thanks so much for the help!
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic