• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic