Solved

Reading individual fields in an FTP input Stream

Posted on 2004-08-10
2
247 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
[X]
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
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 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:

734 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