How to download a text file from the server

hi everyone,
can anyone tell me how to download and read a text file from the server and saved in into resource folder.
with regards
pallavi

its really easy
To read from server, use something like:
HttpConnection connector = null;
InputStream inp_stream = null;
OutputStream out_stream = null;
void CloseConnection()
     if(inp_stream!=null)inp_stream.close();
     inp_stream=null;
     if(out_stream!=null)out_stream.close();
     out_stream=null;
     connector.close();
     connector = null;
public void getResponse(String URL,String params)
  try
     if(connector==null)connector = (HttpConnection)Connector.open(URL);//URL of your text file / php script
     connector.setRequestMethod(HttpConnection.POST);
     connector.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.1");
     connector.setRequestProperty("content-type", "application/x-www-form-urlencoded");
     //connector.setRequestProperty("charset","windows-1251");
     //*** If you need to send ("arg1=value&arg2=value") arguments to script use this:
     out_stream = connector.openOutputStream();
     byte postmsg[] = params.getBytes();
     out_stream.write(postmsg);
     int rc = connector.getResponseCode();//in any case here connection will be opened & closed
     if (rc != HttpConnection.HTTP_OK)
          CloseConnection();
          throw new IOException("HTTP response code: " + rc);
     inp_stream = connector.openInputStream();
     int pack_len = inp_stream.available();
     byte answ[]=new byte[pack_len];
     inp_stream.read(answ);
     CloseConnection();
     ProcAnswer(answ);//process received data
  catch(Exception ex)
     System.err.println("ERROR IN getResponse(): "+ex);
} And you can read from resource file like
public void loadFile(String filename)
    DataInputStream dis = new DataInputStream(getClass().getResourceAsStream("/"+filename));
    String str="";
    try
         while (true)
            ch = dis.read();//read character
            if(ch=='\r')continue;//if file made in windows
            if(ch=='\n' || ch==-1)//end of line or end of file
                if(str.length()==0)continue;//if empty line
                //do some thing with "str"
                if(ch==-1)break;//it was last line
                str="";//next line
                continue;
             str+=(char)ch;
       dis.close();
   catch (Exception e)
       System.err.println("ERROR in loadFile() " + e);
}Welcome! =)
Edited by: MorskoyZmey on Aug 14, 2008 3:40 AM

Similar Messages

  • How to download a pdf file from the server from an strut application?

    Hi,
    I wan to download a pdf file from the server side to local system. Please help me how i use the down load option.

    Read up on the Struts download action [1].
    And next time, please post in the relevant forum, one of the web-tier ones [2].
    [1] http://wiki.apache.org/struts/StrutsFileDownload
    [2] http://forum.java.sun.com/category.jspa?categoryID=20
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    ----------------------------------------------------------------

  • How to Save a text file in the server?

    hello
    i just want to save an text file in the server.
    My idea is to load an xml text file maybe make some changes
    and then save it back to the server, so i can avoid all the
    database/php work because i know nothing about it.
    thank you

    hello
    i just want to save an text file in the server.
    My idea is to load an xml text file maybe make some changes
    and then save it back to the server, so i can avoid all the
    database/php work because i know nothing about it.
    thank you

  • Downloading a text file from application server

    Hi Freinds,
    I am genarating a text file in our application server (Folder /usr/sap/dbi/) I need to download this text file in my destop pc or some other windows server.
    What do I have to do? What is the procedure, Pls help.
    If someone have sample code, pls send.
    We are running SAP ECC5.0 on an iSeries (AS/400) Database DB2/400.
    Regards
    Thanura

    Hi,
    try this:
    REPORT ZGRO_TEST.
    DATA: DATEI_A(30) TYPE C VALUE '/tmp/matnr.txt'.
    DATA: DATEI_PC TYPE STRING VALUE 'C:\MATNR.TXT'.
    DATA: ITAB        TYPE TABLE OF MARA WITH HEADER LINE.
    START-OF-SELECTION.
      PERFORM DATEI_EINLESEN.
      PERFORM DATEI_DOWNLOAD.
    FORM DATEI_EINLESEN.
      OPEN DATASET DATEI_A FOR INPUT IN TEXT MODE.
      IF SY-SUBRC NE 0. STOP. ENDIF.
      DO.
        READ DATASET DATEI_A INTO ITAB.
        IF SY-SUBRC <> 0. EXIT. ENDIF.
        APPEND ITAB.
      ENDDO.
      CLOSE DATASET DATEI_A.
      IF SY-SUBRC NE 0. STOP. ENDIF.
    ENDFORM.                    "DATEI_EINLESEN
    FORM DATEI_DOWNLOAD.
    Datei downloaden
      CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
        EXPORTING
          FILENAME                = DATEI_PC
          FILETYPE                = 'ASC'
        CHANGING
          DATA_TAB                = ITAB[]
        EXCEPTIONS
          FILE_WRITE_ERROR        = 1
          NO_BATCH                = 2
          GUI_REFUSE_FILETRANSFER = 3
          INVALID_TYPE            = 4
          NO_AUTHORITY            = 5
          UNKNOWN_ERROR           = 6
          HEADER_NOT_ALLOWED      = 7
          SEPARATOR_NOT_ALLOWED   = 8
          FILESIZE_NOT_ALLOWED    = 9
          HEADER_TOO_LONG         = 10
          DP_ERROR_CREATE         = 11
          DP_ERROR_SEND           = 12
          DP_ERROR_WRITE          = 13
          UNKNOWN_DP_ERROR        = 14
          ACCESS_DENIED           = 15
          DP_OUT_OF_MEMORY        = 16
          DISK_FULL               = 17
          DP_TIMEOUT              = 18
          FILE_NOT_FOUND          = 19
          DATAPROVIDER_EXCEPTION  = 20
          CONTROL_FLUSH_ERROR     = 21
          NOT_SUPPORTED_BY_GUI    = 22
          ERROR_NO_GUI            = 23
          OTHERS                  = 24.
      IF SY-SUBRC NE 0. STOP. ENDIF.
    ENDFORM.                    "DATEI_DOWNLOAD
    Regards, Dieter

  • How can I read text files from LAN if I only know the hostname?

    I'm new in Java Developing, and dont know the written classes yet. I need help, how to do the following steps?
    <p>1. How can I read text files from LAN if I only know the hostname, or IP address?
    <p>2. How to read lines from text files without read all lines from the beginning of file, just seek to a position.
    (ex. how can I read the 120th line?)
    <p>Please help!
    <p>sorry for the bad english

    I'm new in Java Developing, and dont know the written classes yet. I need help, how to do the following steps?
    1. How can I read text files from LAN if I only know the hostname, or IP address?You need to know the URL of the file. You need to know the hostname, port, protocl and relative path.
    The hostname is server, not file.
    2. How to read lines from text files without read all lines from the beginning of file, just seek to a position.Use the seek() to get to a random byte.
    (ex. how can I read the 120th line?)The only way to find the 120th line is to read the first 120 lines. You can use other file formats to find the 120th line without reading the whole file but to need to be able to detremine where the 120th line is

  • Hi. I have Lightroom 4 installed. I cannot download my CR2 files from the Canon 5D Mark III camera. I have downloaded Lightroom 5 thinking it was an update but it appears I have to pay for the program. Any ideas how I can get lightroom 4 to accept my CR2

    I have Lightroom 4 installed. I cannot download my CR2 files from the Canon 5D Mark III camera. I have downloaded Lightroom 5 thinking it was an update but it appears I have to pay for the program. Any ideas how I can get lightroom 4 to accept my CR2 files ?

    The Canon 5D Mk 111 was supported from LR 4.1, see the link below. Just update LR to the latest version. See link below
    Camera Raw plug-in | Supported cameras
    Adobe - Lightroom : For Windows
    Adobe - Lightroom : For Macintosh

  • How to upload a text file from a shared folder and provide an o/p

    how to upload a text file from a shared folder and provide an o/p  containing the details in each order in the text file

    Hi,
    Use <b>GUI_UPLOAD</b> to upload a text file from a shared folder.
    Use <b>GUI_DOWNLOAD</b> to download data in a file on the presentation server or use <b>OPEN DATASET, TRANSFER</b> and <b>CLOSE DATASET</b> statements to download data to the application server.
    Now, I hope the code for data fetching, if required, is already present in the report.
    Reward points if the answer is helpful.
    Regards,
    Mukul

  • How do I move music files from the startup disc to iTunes in the other internal hard disk os 10.5.8?

    How do I move music files from the startup disc to iTunes in the other internal hard disk os 10.5.8?
    The music I want to move was in iTunes but is now just files. I had to reinstall a new iTunes and lost all my old music.
    Thank you!

    That article is about using your iPod as an external hard drive, to move files from one computer to another computer.  It is not related to your question.
    You can't use iTunes to move song files from iPod to computer, except for songs you purchased from the iTunes Store (and you can also re-download purchases).  However, there are third-party methods and utilities that can move song files from iPod to computer.  If you do a Google search on something like "ipod transfer," you should get some links.
    Once the song files are on your current computer, add them to that computer's iTunes library by dragging the files (or folder containing the files) to the iTunes window.  After confirming everything is there (and fixing the data issue you mentioned) you can sync the iPod.  You may want to do a Restore on the iPod, if it might have a data corruption issue, which will erase the iPod's hard drive, re-install the latest software, and set it to defautl settings.

  • Download text file from application server to client server.

    Hi all,
    I am facing a format issue while downloading text file from application server to the client machine.
    The issue is that, say I have 6 to 10 lines in my text file in application server. but when i store it on the hard drive,
    it shoes all the data in a single line. Where as i need to download data in same format as in application server.
    Awaiting for your responses.
    Regards,
    Jose

    Hi,
    If we want to upload file data from the application server to the internal table, there is no function module or class static method which we can use, we must wirte the code by ourselves.
    1. For the file data which has no seperator between field columns.
    PARAMETERS p_file  TYPE dxfile-filename.
    START-OF-SELECTION.
    OPEN DATASET p_file IN TEXT MODE ENCODING DEFAULT FOR INPUT.
      DO.
        READ DATASET p_file INTO gds_data.
        IF sy-subrc <> 0.
          EXIT.
        ENDIF.
        APPEND gds_data TO gdt_data.
      ENDDO.
    CLOSE DATASET p_file.2. For the file data which has tab separator between field columns.
    DATA: gds_field_split type gts_data.
    FIELD-SYMBOLS: <fs_field> TYPE gts_data.
    PARAMETERS p_file  TYPE dxfile-filename.
    START-OF-SELECTION.
    OPEN DATASET prf_file IN TEXT MODE ENCODING DEFAULT FOR INPUT.
      DO.
        READ DATASET p_file INTO gds_field.
        SPLIT gds_field  AT cl_abap_char_utilities=>horizontal_tab
             INTO TABLE gdt_field_split.
       LOOP AT gdt_field_split  into gds_field_split.
           gdf_index = gdf_index + 1.
           ASSIGN COMPONENT gdf_index OF STRUCTURE
                 gds_data to <fs_field>.
          IF sy-subrc = 0.
              <fs_field> = gds_field_split.
          ENDIF.
       ENDLOOP.
        APPEND gds_data TO gdt_data.
      ENDDO.
    CLOSE DATASET p_file.
    Thanks & regards,
    ShreeMohan

  • How do I open RAW files from the Nikon D4s in photoshop?

    How do I open RAW files from the Nikon D4s in Photoshop? I have the updated newest version.

    The Nikon D4S is a brand new camera which has just been added by Adobe to Camera Raw 8.4.
    http://labs.adobe.com/technologies/cameraraw8-4/?tabID=details#tabTop
    8.4 has not yet been finally released but you can download and install a pre-release copy for CS6 and CC (it is not compatible with CS5 and earlier)
    CS6:http://labs.adobe.com/technologies/cameraraw8-4/
    CC: http://labs.adobe.com/technologies/cameraraw8-4-cc/

  • Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the rows? Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the records?
    Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    The Oracle documentation has a good overview of the options available
    Generating XML Data from the Database
    Without knowing your version, I just picked 11.2, so you made need to look for that chapter in the documentation for your version to find applicable information.
    You can also find some information in XML DB FAQ

  • How do I delete a file from the Adobe Reader for iOS?

    How do I delete a file from the Adobe Reader for iOS?

    Read this:
    http://forums.adobe.com/thread/1012973?tstart=0

  • How can open a html, pdf files from the server (c:\foldername\filename)

    Hi all,
    I am developing an application. in this app i have to implement RMI.
    My problem is this, How can a client open a files from the server.
    all the html, pdf files are stored in the server's directory like C:\audit\filename.
    There is a folder on the server's C directory which contains all the html , pdf files.
    please tell me how can a client open a file from the server using RMI.
    Please send me the solution as soon as possible.
    Thanks & Regards
    Bhavishya

    That's doing it the hard way. Why not use HTTP or FTP?

  • How do I move aiff files from the viewer to the timeline-it is not working when I try to drag and click or clicking on overwrite or insert in Final Cut Pro 7. Thanks

    How do I move aiff files from the viewer to the timeline-it is not working when I click and drag or when I try to move the files to the overwrite or insert buttons-Thanks.

    hi
    You cannot move audio from the viewer
    Mark your in and out points then in the browser grab hold of the audio tracks icon and drag that to the time line
    PJ

  • HT2203 How do I export a file from the new iMovie 10.0.2 to iPod size?

    How do I export a file from the new iMovie 10.0.2 to iPod size? I used to be able to do this and it would save as a m4v file but I can no longer do this and the files are too big.

    iTunes: May be unable to transfer videos to iPhone, iPad, or iPod
    iTunes: Frequently asked questions about viewing and syncing videos
    You may need a third-party computer app like HandBreak. That one is free and has preset outputs for iOS devices

Maybe you are looking for

  • How to hide Jump list's Tasks in Windows 7 using userChrome.css

    How to hide Jump list's Tasks in Windows 7 using userChrome.css

  • Crystal report: client-side printing problem

    Hello everyone, I developed an asp.net web application / c # - VS2012 - crystal Repport (CRforVS_13_0_5) on windows 7 pro 32 bits, everything is ok even print reports. The problem is that when hosting the web application in IIS on the same machine (W

  • Oracle Application Server 10g Standalone Installation

    Hello, Can you please let us know if it is possible to Install Oracle Application Server (10g) Standalone ( without SOA suite 10g). If there is any documentation/link which can provide this information. Thanks, Hussain PIM Dev Team

  • Terminal window scrolling buffer

    (If anyone wants to know the crazy thing I'm up to, I'll try to explain.) I'm interested in finding out the following about the terminal window scrolling buffer: • The buffer's size evidently would be specified in lines. As received in MAC OS, is it

  • ITunes deletes his own library every now and then .....

    It happened already a couple times that iTunes has no songs in the list. iTunes is when i start it just like new. not one song or playlist in the database. The strange thing is, that all songs can be found in the iTunes Music folder. I can add them a