Solved

Reading individual fields in an FTP input Stream

Posted on 2004-08-10
2
252 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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:
Suggested Courses

623 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