How to write to a text file using FTPClient in Java

Posted on 2008-10-08
Last Modified: 2013-12-02
I am trying to convert an XML file into a text file in the server. I am able to read the xml file using SAX parser, I am storing it in CharArrayWriter. But I am having problem writing this character array to a text file.  I don't know which output stream should be used.
// Buffer for collecting data from the "characters" SAX event.

    private CharArrayWriter contents = new CharArrayWriter();

// SAX events go here... The characters are stored in contents.

inputFtp = new FTPClient();

outputFtp = new FTPClient();



inConn = inputFtp.login("bbb", "ccc");

outConn = outputFtp.login("bbb", "ccc");


// Create SAX 2 parser...

XMLReader xr = XMLReaderFactory.createXMLReader();

// Set the ContentHandler...       

ProcessXMLtoTextinServer XMLtoText = new ProcessXMLtoTextinServer();

xr.setContentHandler( XMLtoText );



is = inputFtp.retrieveFileStream("test.xml");


int reply=inputFtp.getReplyCode(); 


//"Connected Successfully to the FTP server"); 


//"Connection to the FTP server Failed"); 





// parse the file...

xr.parse(new InputSource(new InputStreamReader(is )) );   

os = outputFtp.storeFileStream("test.txt");

OutputStreamWriter osw = new OutputStreamWriter(os,XMLtoText.contents.toString());   //The problem is in this line.

BufferedWriter out = new BufferedWriter(osw);


Open in new window

Question by:jkrishna01
  • 2
LVL 17

Expert Comment

ID: 22672923
should be something like

os = outputFtp.storeFileStream("test.txt");
LVL 17

Accepted Solution

contactkarthi earned 500 total points
ID: 22672945
ftp:// got appeneded in the previous post for some reason....

below is the one i wanted you to try

os = outputFtp.storeFileStream("test.txt");

Featured Post

Do email signature updates give you a headache?

Are you constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping2 challenge 13 80
eclipse shortcuts 9 45
ForLoop Example 3 40
Windows 10 IE Certificate Issue 10 41
Goal:  To set up a secure SSH server for your home computer to make it accessible anywhere AND to use it as a port forwarding proxy. Steps 1.  WinSSHD version 5 is free for personal use.  So download and install it.  You can download it from the…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now