Solved

Reading individual fields in an FTP input Stream

Posted on 2004-08-10
2
225 Views
Last Modified: 2010-03-31

Hi I have a java method which uses a streaming FTP connection to a remote file. My problem is that I do not know
how  split the buffer read in into individual fileds  so I can manipulate them.  The code is as follows:

NB I have entered another related question to this problem recently, but that  requires more comprehensive design details and this one is specific to geting the data from the input stream.


public static boolean getDataFiles( String _host,String _user,String _password,String destinationFolder,String strDate)  {
       try
       {      
                      
             String host= _host;  String user= _user;  String password= _password;
             URLConnection  urlc = null;
            
             String targetfile= ""Data" + strDate + "_v4.dat";
          
             URL url = new  URL("ftp://"+ user+ ":"+ password+ "@"+ host+ "/"+ targetfile+ ";type=i");    
             urlc = url.openConnection();
             urlc.setDoInput(true);
             InputStream is = urlc.getInputStream();

             byte[] buf= new byte[16384];
             for(int br = is.read(buf); br > -1; br = is.read(buf))
             {
                                                  //**** get individual fields from buffer delimited by comma***
                   //System.out.write(buf, 0 , br);
                  
             }
             is.close();
                   
       }
       
       catch (Exception E)
       {
             System.err.println(E.getMessage());
             E.printStackTrace();
       }      

       return true;  
      
 }

Thanks

azsat
0
Comment
Question by:azsat
  • 2
2 Comments
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 500 total points
Comment Utility
byte[] buf= new byte[16384];
           for(int br = is.read(buf); br > -1; br = is.read(buf))
           {
                                                  //**** get individual fields from buffer delimited by comma***
                 String str=new String(buf);
                 String fields[]=str.split(",");
                  for(int kk=0;kk<fields.length;kk++)
                    {
//ur furher code
                   }

                //System.out.write(buf, 0 , br);
               
           }
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility
glad to help :-)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumHeights2  challenge 7 75
wordlen challenge 3 46
Java / Linux and Regular Expressions 11 42
thymeleaf natural templating vs JSP 2 22
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

763 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

12 Experts available now in Live!

Get 1:1 Help Now