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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Maven Project: Hibernate Dependencies Conflict 10 52
ejb example issues 3 53
Java Restore security prompts not working 10 135
java example issue 5 45
If, like me, you have a lot of Dell servers in the estate you manage this article should save you a little time. When attempting to login to iDrac on any server I would be presented with two errors. The first reads "Do you want to run this applicati…
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 will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

733 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