Solved

Reading individual fields in an FTP input Stream

Posted on 2004-08-10
2
226 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
ID: 11765649
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
ID: 11766479
glad to help :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

920 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