Read content of file which is ZIPed

I need to read contents of a file which is present in ZIP file.
The zip file is present on online server. I am able to get the Zip Input stream for the Zip file and also able to retrive the file names which are present but when I am trying to retrive the content of file is get a String which has only the file names of the zip. Please suggest what to do.
Following is my Code.
// aConn.getInputStream() Gives me access to Zip file present on online Server
ZipInputStream fileIn = new ZipInputStream(aConn.getInputStream());
             anEntry = inputStream.getNextEntry();
             if (anEntry != null) {
                  String filename = arEntry.getFilename();
                                        byte[] b = new byte[2024];
                  fileIn.read(b);
                             sb.append(b.toString());
             }

Reading an input stream into an array of bytes and then calling toString() on that byte array isn't going to give you the contents of the input stream meaningfully. For one thing it might not even be textual data. And secondly that's not how you get textual data.
A better approach would probably be to get the number of bytes of the given entry from the ZipEntry.getSize method, create a byte array of that size, load only that many bytes, and then (if you're sure it's text data) send the byte array to a String constructor. Or you could use a java.io.ByteArrayOutputStream for that. Note that you'll need to know the character encoding for this.

Similar Messages

  • How to read an excel file which contains multiple tabs using File adapter

    Hi BPEL gurus,
    I have a requirement where i need to read an EXCEL file, which has three tabs inside the file. All the three tabs has data in it. I have seen few examples where file adapter reads an excel file with data present inside a single tab but not with multiple tabs.
    If anyone has worked on this scenario, please provide your suggestions/inputs/links etc.
    Thanks in advance

    hi Sathish,
    this might help
    PI/XI: Reading MS Excel's XLSX and XLSM files with standard PI modules - easily...
    thanks and regards,
    Praveen T

  • Read contents of file into outputstream

    Can anyone suggest that what are the best methods to read contents of a file (better cater to both conditions: big file size and small file size) into outputstream and send through socket...
    Thanks.

    Thanks for the answer. But I would like to ask the following question:
    I have a VB application which generates a file. I have a Java application which read the contents of the file.
    is it possible that VB side calls the read() (file) and send() (through socket to destination) methods in Java application once the file is generated? Actually my objective is VB is responsible for generating a file for Java application to read data from and then send the data (not file) to destination....If it is impossible to achieve, any alternative to achieve this?
    Thanks
    Edited by: whkhoo on Jun 15, 2008 8:45 PM

  • How to read contents of files that do not fall under public security group?

    Hi,
    I need to read the contents of a WCM based xml file that does not fall under public security.
    The process is like this:
    First the user makes chnages to the content.
    The workflow will be triggred based on the security group metadata that is associated with the content.
    Once the content is finally approved our workflow calls a custom idoc script.
    First we tried directly reading the xml contents from the idoc script which was still in the context of workflow. But since content item is still in workflow I was not able to read the changes. So I created a separate content publisher thread and read the DOC_INFO and checked for the dStatus value. If the value is RELEASED then I reading contents by calling ssIncludeXml idoc script.
    This was working fine for public content. But now the requirement is that all content cannot be public. Content authors should not be able to edit the content that does not belong to their group, So we created security groups (and roles) and are associating that groups to the relavent content.
    Beacuse of this change I am not not able to read the non public content. The call to DOC_INFO_BY_NAME service, which gives all the content files' metadata, is expecting the user to be logged in to give the details.
    I tried calling the CHECKIN service with sysadmin and captured the cookies returned by that service and use cookies for the DOC_INFO_BY_NAME service call. But the service call was faling. It is throing the 401 forbidden error with the message that user needs to be logged in to get the details.
    How to address this problem. Someone please help.
    Note: I also tried using ridc for this. I was able to get it working but since it is executing in the context of server ridc api is changing server's environment properties like HTTP_HOST, HTTP_CGIPATHROOT etc. It also seemed like system was becoming non functional after using ridc. When I called check-in the system metadata values like security group are no more loading. Not sure if ridc is the culprit here but worried that it might be causing this issue.
    Regards,
    Pratap

    Sorry, I posted too much details while posting this question. I was saying "not able to read *non* public content".
    Anyway, I was able to resolve the issue. I was able to authenticate with sysadmin credentials in the request to service using basic authentication and was able to read doc info with that credential.
    But I realized there is more than option for reading secure content.
    - I could set user name as sysadmin in the m_environment (if I am in the context of a service) and the call the DOC_INFO_BY_NAME service.
    - I can post an HTTP request to DOC_INFO_BY_NAME service with sysadmin credentials and do basic authorization via the connection. (This is what i have done successfully as of now )
    - I could add guest role to all security groups with R (read) privileges.
    I will look into all options and implement the one which is more apt.
    Regards,
    Pratap

  • Reading Contents of File and displaying output

    I'm trying to read the contents of a file, then loop through the contents, perform some formatting, and display the output. Should I read the file into an array? What is the best approach? Thanks in advance.

    Depends. Is it a text file? Can you format each line independent of others? If so, you can just read one line at a time (BufferedReader) and pass it to wherever the display is. If you need to work on the file as a whole, then you need read it all at once.

  • Adobe Reader leaving temp files, which are not auto-deleting.

    Adobe reader is leaving temp files all over and I can't delete them. The temp files are left in my "My Documents" folder, which is redirected to the server. Anytime I open a PDF, it leaves a temp file (ie:U17F7.tmp) and it does not auto-delete. The temp files are 0 bytes in size, just really annoying when my folders get cluttered with all these temp files.  I also cannot delete the files, because it says the location is incorrect. I am able to delete the temp files when I'm not connected to the company network. How do I get these temp files to remove themselves once I close out of Adobe Reader?  This is driving me crazy!

    Hi burdurboy05
    What is the version of reader that you're using?
    Are you trying to print files ?
    Did you try to uninstall and re-install the product?
    ~Mandy

  • Read contents of file

    hello,
    i want to read the contents of an image file without really opening it. i know this can be achieved by reading the header and footer of the file. this header and footer contain details regarding the contents of the image file. with this i can know the pixel arrangement of the image. how can i acieve this?
    asrar

    You could use a RandomAccessFile object if you know the size in bytes of the header and footer. For the header you would read the first X number of bytes where X is the length of the header. For the footer you'd use the "seek" method to seek to the L - Y point in the file where L is the length of the file obtained using File.length() and Y is the length of the footer. Then read the remainder of the file.
    You could also use the new Java NIO package to read the various parts of the image file directly into byte buffers. You'd create two ByteBuffers big enough to hold the header and footer and a third that contains the rest of the file. Check out the java.nio.channels.FileChannel class.
    But the guy who posted before is right in that you have to open the file if the header and footer are part of the file.

  • Read contents of file into outputstream and send through socket

    I have a file. Instead of transferring the whole file through socket to the destination, I will read the contents from the file (big or small file size) into outputstream and send them to the destination where the client will receive the data and directly display it....
    Can you suggest any efficient way/methods to achieve that?
    Thanks.

    I don' t understand what you think the difference is between those two techniques, but:
    int count;
    byte[] buffer = new byte[16384];
    while ((count = in.read(buffer)) > 0)
      out.write(buffer, 0, count);
    out.close();
    in.close();

  • I get on 5.7 the following -- Some import operations were not performed -- then states it connot read the following files (which were all of my pictures) this is happening on a T3 and 6D

    it conn

    "cannot be read" usually means that the destination directory (as shown in the Import dialog box, in the Destination Panel) has either
    been accidentally changed, so change it back to whatever it used to be; or
    does not have WRITE permission, so change your permissions on that directory

  • How to read a file which content hindi characters.....

    I m reading a text file which content hindi characters.... but m nt getting the right result. It shows garbage instead of hindi characters.
    plz somebody help me....:(

    You posted this in the XML forum. Is this an XML file you are asking about?
    And we need definitions for some of the terms you used in your original post. You said "it shows garbage". We need to know:
    1. What is the "it" there?
    2. How does it "show" something?
    3. What does the "garbage" look like.
    In future you will find you get better answers if you write better questions.

  • I want to read a file which is in a zip and this zip file is at ftp site

    i am facing this problem and try to find the solution from last month please help me
    i want to read a file which in ziped and this zip file is at ftp site. and i want to read this file without downloading this zip file to local machine. i have to read it from ftp location only

    You can open an URLConnection to a file on an FTP server (search this forum to find out how). You can get the InputStream from the URLConnection and feed it to ZipInputStream. That should do the job.

  • Unzip File and Read Contents

    Hi,
    I want to unzip a file(called outer.zip) present on the Presentation server and read inner.zip file which lies within the outer.zip.
    i wrote the following program, but i am getting an error in the last step .Can some one tell me themistake i am committing here:
    TYPES : BEGIN OF sda_content,
      lv_buf(65535) type x,
      END OF sda_content .
    DATA : ls_sda_content type sda_content ,
            lt_sda_content type table OF sda_content  .
    DATA : lv_file_length type int4 .
    DATA : x_buf TYPE xstring .
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename                      = 'C:\outer.zip'
       FILETYPE                      = 'BIN'
    IMPORTING
       FILELENGTH                    = lv_file_length
      tables
        data_tab                      = lt_sda_content
    CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
      EXPORTING
        input_length       = lv_file_length
    IMPORTING
       BUFFER             = x_buf
      tables
        binary_tab         = lt_sda_content
    clear : lt_sda_content ,lv_file_length,x_buf .
    data : cl_inst type ref to cl_abap_zip .
    CREATE OBJECT cl_inst.
    CALL METHOD cl_inst->load
       EXPORTING
         zip             = x_buf.
    CALL METHOD cl_inst->get
      EXPORTING
        NAME                    = 'inner.zip'
      IMPORTING
        CONTENT                 = x_buf.
    Thanks and Regards,
    Gaurav

    Hi Gaurav Rathi  ,
    Even am facing some problem .I cannot open the ZIP file? Can you please tell me where exactly you have corrected your mistake?
    Thanks
    Dan

  • I recently purchased a Mac 0S X 10.6.6 which was an upgrade from the Mac OS 1.4.1.1  I downloaded the adobe ph otoshop CS2 which I had on my old computer and now it cannot read my NEF files.  Which is a RAW file from my Nikon.  Can anyone help...please?

    I recently purchased a Mac OS X 10.6.6 which was an upgrade from my Mac OS version 10.4.1.1  I downloaded the Adobe Photoshop CS2 which I had on my old computer and now it cannot read my NEF files which is a RAW file from my Nikon D200.  I did not have this problem on my old Mac.  I always shoot RAW and can't open any photos.  Can anyone help me PLEASE?!? 

    Do you have access to another Mac to see if the disk can be read by it?  If it can't then you're pretty sure it's the disk. If it can then there may be issues with your optical drive which might be cleared up by using a cleaning disk on it, one that uses dry brushes (no liquid).
    If you have access to another Mac and it can read the iWork disk make a disk image of it so you can move the disk image to your iMac and install from the disk image.
    OT

  • Read from File which is dynamically updated

    Hello all
    Is there any class for reading from a file which is dynamically updated?and those updates are immediatley reflects in java File object without closing previous and reopen that file again to get the latest updates?
    thanks
    sjafery

    I meant RandomAccessFile

  • Reading a binary file to string variable does not populate correctly

    Hi, I am new to Adobe Air/Flex and I'm trying to read a
    binary file which also contains text in "cleartext". The problem
    I'm having is that when I call FileStream.readUTFBytes method, only
    the first 6 characters are showing up in my string variable
    "contents" when I debug it in FlexBuilder or use a trace command
    and debug it. I have also tried with other types of files but I
    have a similar problem unless it's a non-binary file.
    Am I doing something incorrectly or should I be reading a
    binary file differently than the way I'm reading it currently?
    The source code is shown below.
    TIA,
    Magnus
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:Script>
    <![CDATA[
    import flash.filesystem.File;
    private function readFiles():void{
    var feedFile:File = File.userDirectory.resolvePath( "Local
    Settings/Application Data/Microsoft/Feeds/AppScout~.feed-ms" );
    var stream:FileStream = new FileStream();
    stream.open( feedFile, FileMode.READ );
    var contents:String =
    stream.readUTFBytes(stream.bytesAvailable);
    trace(contents);
    stream.close();
    ]]>
    </mx:Script>
    <mx:Button x="121" y="66" label="Button"
    click="readFiles()" />
    </mx:WindowedApplication>

    It's difficult to tell what it is, it looks like a binary
    pipe symbol but I can copy it from TextPad for example. Some of the
    characters following it cannot be copied from TextPad which I
    assume is because it's null. I can read the whole file in C#/.Net
    and assign it to a string variable without any problems but perhaps
    Air is somewhat limited to binary content.

Maybe you are looking for

  • KM Scheduler is not working

    Hi Experts, I created a KM scheduler task in NWDS and deployed into portal. The same task is working in one system ie. in DEV.  But its not working in QUA system. I Deployed the same into QUA. I selected the CM and time interval but its not working.

  • Can my wife and I share iCloud on common iPad?

    My wife and I both have I Phones (3g). I have a new Macbook Pro and she has a 4 year old Macbook. We have a new I Pad. Can we share contacts, tunes, calendars, etc in the I Pad via I Cloud?

  • How do i compare the similarities between two or more text files?

    The subject says it all. I am familiar with a number of the diff tools that are available, but I have yet to find a tool or app that will find the similarities between two text files. Any suggestions?

  • What are the ways in data transfer

    Hi Experts, What are the ways to transfer data from SAP R/3 to SAP BW and SAP BW to SAP APO DP? Can anyone help me please. Regards Suvi

  • How to modify warning/error messages in DM

    Hi, in most of the DM packages a pop-up is generated stating one should enter more variables or something in case one did not enter any selections for any of the dimensions (for example in a copy of move package ...). Does anyone has an idea, where t


HashFlare