Solved

Reading individual fields in an FTP input Stream

Posted on 2004-08-10
2
232 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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

831 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