Get file name

Hello world,
Am writing a small server application that can accept files and save them locally. Now, the server is working, but am finding it very hard to get the name of the file that's been sent so that I can save the file with that name and its extension.
e.g. I want if I sent a hello.java file, then, the server will save it as hello.java. But at the moment, its not saving it like that because there is no way can get the name of the file from the client.
Here is my code:
import java.io.*;
import java.net.*;
class Server {
    static final String ToSave = "C:\\";
    static final int PORT               = 2391;
    public static void main(String args[]) {
        while ( true ) {
            try {
                ServerSocket socketServer = new ServerSocket(PORT);
                Socket socket = socketServer.accept();
                //Assuming we have a file name (FILENAME)from client
                FileOutputStream fos = new FileOutputStream(ToSave + FILENAME);//<--HERE IS WERE i WANT THE FILENAME
                BufferedOutputStream out = new BufferedOutputStream(fos);
                BufferedInputStream in = new BufferedInputStream( socket.getInputStream() );
                int i;
                while ((i = in.read()) != -1) {
                    out.write(i);  
                out.flush();
                in.close();
                out.close();
                socket.close();
                socketServer.close();
                System.out.println("Transfer complete.");
            catch(Exception e) {
                System.out.print(  e  );
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ie) {
                System.err.println("Interrupted");
}

You have to define a protocol which enables the
client to tell the server the file name.
BTW creating server sockets inside a loop is not a
good idea.
Thank you very much :)
I've got the idea on how to implement it now. All I have to do is:
first connect to the server and send a message containing the name of the file and then, at the server end, I will receive the name and use it to save to incoming file.
Thanks again.

Similar Messages

  • GET FILE NAME C:\temp\ADIBO.txt

    Hi,
    How to get file name?
    I used Get_File_NAME, but I'am getting an error.
    lv_lfilename is not the type LOGICAL_FILENAME
    C:\temp\ADIBO.txt
    I need to get  ADIBO ??
    tnh, Adibo..:)
    I am using this code to download file and after that I need to get FILE_NAME:
    DATA:  lv_lfilename TYPE string.
    PARAMETERS:
      pa_lfile TYPE zlocalfile
               DEFAULT 'C:temp'.
        CONCATENATE pa_lfile ''INTO lv_lfilename.
        CALL FUNCTION 'GUI_DOWNLOAD'
             EXPORTING
                  filename = lv_lfilename
                  filetype = 'ASC'
             TABLES
                  data_tab = it_billit_down.
        IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.

    Hii..
    You have to Maintain the Logical filenames and their Physical Paths in Tcode FILE.
    Then create a program like this..
    REPORT  ZSEL_FILES1.
    DATA : V_LOGFILE TYPE STRING.
    DATA :V_PHYFILE TYPE STRING.
    DATA : ITAB TYPE TABLE OF SCARR.
    START-OF-SELECTION.
    SELECT * FROM SCARR INTO TABLE ITAB.
    **To get the Physical file based on the Logical file names - Maintained in Tcode FILE
    CALL FUNCTION 'FILE_GET_NAME'
      EXPORTING
       CLIENT                        = SY-MANDT
        LOGICAL_FILENAME              = VlOGFILE
      OPERATING_SYSTEM              = SY-OPSYS
      PARAMETER_1                   = ' '
      PARAMETER_2                   = ' '
      PARAMETER_3                   = ' '
      USE_PRESENTATION_SERVER       = ' '
      WITH_FILE_EXTENSION           = ' '
      USE_BUFFER                    = ' '
      ELEMINATE_BLANKS              = 'X'
    IMPORTING
      EMERGENCY_FLAG                =
      FILE_FORMAT                   =
       FILE_NAME                     = V_PHYFILE
    EXCEPTIONS
      FILE_NOT_FOUND                = 1
      OTHERS                        = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    **To download the file to PC.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
      BIN_FILESIZE                    =
        FILENAME                        = V_PHYFILE
       FILETYPE                        = 'ASC'
      APPEND                          = ' '
       WRITE_FIELD_SEPARATOR           = 'X'
      HEADER                          = '00'
      TRUNC_TRAILING_BLANKS           = ' '
      WRITE_LF                        = 'X'
      COL_SELECT                      = ' '
      COL_SELECT_MASK                 = ' '
      DAT_MODE                        = ' '
      CONFIRM_OVERWRITE               = ' '
      NO_AUTH_CHECK                   = ' '
      CODEPAGE                        = ' '
      IGNORE_CERR                     = ABAP_TRUE
      REPLACEMENT                     = '#'
      WRITE_BOM                       = ' '
      TRUNC_TRAILING_BLANKS_EOL       = 'X'
      WK1_N_FORMAT                    = ' '
      WK1_N_SIZE                      = ' '
      WK1_T_FORMAT                    = ' '
      WK1_T_SIZE                      = ' '
    IMPORTING
      FILELENGTH                      =
      TABLES
        DATA_TAB                        = ITAB
      FIELDNAMES                      =
    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
      OTHERS                          = 22
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    <b>reward if helpful</b>

  • Error in reciever file adapter , where i am getting file name dynamically

    hi all,
    error in reciever file adapter , where i am getting file name dynamically, please help me in this isssue , i am trying for a long time
    MP: Exception caught with cause com.sap.aii.af.ra.ms.api.RecoverableException: Exception in XML Parser (format problem?):'java.lang.Exception: Message processing failed in XML parser: 'Conversion configuration error: Unknown structure 'ns0:MT_eINVOICE_RECV' found in document', probably configuration error in file adapter (XML parser error)': java.lang.Exception: Exception in XML Parser (format problem?):'java.lang.Exception: Message processing failed in XML parser: 'Conversion configuration error: Unknown structure 'ns0:MT_eINVOICE_RECV' found in document', probably configuration error in file adapter (XML parser error)'

    i am getting new error
    MP: Exception caught with cause com.sap.aii.af.ra.ms.api.RecoverableException: Channel has not been correctly initialized and cannot process messages
    this is my strcuture
    and i have changed my structure
    <HEADER>
    <ADDRESS1/>
    <ADDRESS2/>
    <ADDRESS3/>
    <ADDRESS4/>
    </HEADER>
    <HEADER_GST>
    <TAX1/>
    <TAX2/>
    <TAX3/>
    </HEADER_GST>
    <LINE>
    <QTY/>
    <UOM/>
    <UNIT_AMT/>
    <CHARGE_TO_DT/>
    </LINE>
    <FILENAME>
         <FILENAME/>
    </FILENAME>
    i have given the recordset structure as
    HEADER,HEADER_GST,LINE,FILE

  • How to get file name of the form attachment?

    Hi,
    is there anybody who is able to help me with the following problem???
    I started my process from Workspace ES and as a first step I attached one locale file (IMG.JPG or IMG.TIF e.g.) as a form attachment. I used "Attachments" bookmark in the Workspace ES.
    I need to get file name of attached file in the process!!!
    I tried to use "getTaskAttachments" component to get file name of form attachment but without success. This component successfully obtained attached file an stored it in the variable (type list, subtype document) but didn't produce all file attribute informations such as basename or Content Type:
    Is there some possibility to obtain file name (including file extension) by using "standard" tools and components of ALC?
    Thanks for your suggestions.

    Hi LekomDev,
    I faced the same situation some time back and this is what I know.
    Based on the file type few of the attributes will or will not be populated. (This is what the official documentation says about Document attributes)
    The file name that you are looking for would mostly be in 'name' attribute of Document object. The 'wsfilename' attribute is the atrribute which gets used to show the file name into Attachments tab of the workspace.
    So, if you are just interested in knowing the filenames then 'name' attribute is the place that you are looking for.
    But if you are trying to solve an issue in which Attachments against a Task isn't showing the filenames properly then you would need to copy the 'name' attribute value into 'wsfilename' attribute and then the Attachmetns against a Task would have the correct names.
    Tip: Use the Record and Playback option of the workbench to inspect the Document variable and you would see all of the values for a Document variable at desired step in your orchestration.
    hope this helps,
    cheers,
    Parth Pandya
    Blog: http://livecyclekarma.wordpress.com

  • Need to get file name and directory back from file adapter - WRITE

    I am using the file adapter to write a file. I want to log the file name of the file we just created. Since we use a precise timestamp in the file name, I can't accurately guess.
    I have an invoke in my BPEL process to the file adapter. My first try was to assign the jca.file.FileName property to a variable, but it never comes back. I looked around and saw plenty of ways to SET the file name for a write and GET the file name for a read, but no GET file name for WRITE.
    Anyone have a solution?
    Thanks in advance!

    I think I got your point... You can tell FileAdapter the filename to write, but if you don't then FileAdapter can not tell you the filename that it wrote... I think it is pretty possible Oracle didn't implement the latter, as the write operation is probably asynchronous and the filename is calculated later on...
    If what you want is just log, you may achieve your requirement by increasing verbosity on Adapter logs... Have a look at the link bellow...
    http://docs.oracle.com/cd/E15586_01/integration.1111/e10226/ad_mon.htm#CJHHBBID
    Otherwise, the solution for you will be to calculate filename yourself, and that will be a little bit of reinventing the wheel... But at least you will know the filename...
    Cheers,
    Vlad

  • Get file name from folder

    Hi all,
    how to find a .txt file in a particular folder. My text file comes with
    following name <fixed_name>.<mmddyy><hhmmss>, e.g., fn_fnprod.102806015605
    so how to get this file name. nd also tell me if there are multiple files
    then how to retrieve the oldest one first and so on....
    Thanks & Regards
    Gaurav

    it's fine but how to know which is older file b'cpz
    this file comes every day with new date & time. so
    what if there a multiple file. nd i have proceed
    oldest first.
    pls help asapget each file last modifed, using file.lastModified() method and compare which file you would be needing. =)

  • Get File name from incoming IDoc

    HI All,
    I am in an IDOC to File scenario using Fcc. (R/3 --> XI --> 3rd party)
    I need to use the  idoc-number(EDI_DC40-Docnum) as my output file name. I planned using variable substitution but there it expects me to get the idoc number from payload which I do not have it in. (refer c ode below)
    As I understand, variable substitution can be used only on payload(the FINAL data set that we will be writing to the file).
    Can we use the data which is part of incoming IDOC and not part of payload(final data what we are writing to file).??
    Other idea was to map this IDOC no to a field in final file, but this field should not be written in the output file, so am confused about how to achieve this.
    E.g
    *Incoming Data*
    IDOC
      |_EDI_DC40
        |_DOCNUM
    Final data (Payload)
    Header
    Data
    Trailer
    As seen in my example above I do not have the IDOC no in the final data so how do I use the Idoc no as my filename? Apprecaite your help on same.
    Regards
    Shirin

    Hi
    You can use dynamic configuration to get the file name .
    Use Adapter Specific Message Attributes for the target Comm Chanel check the indicator for filename in the advanced tab of CC
    create a UDF with i/p as file name  i.e the Idocnum field and
    paste this code
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    //conf.removeAll();
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    //String filename= conf.get(key);
    conf.put(key, fileName);
    key= null;
    return fileName;
    PS: use cache as value in UDF
    ands assign the o/p of this UDF to a root node

  • Get File Name in a package

    Hi,
    I have a interface File to DB. In the source exist many files with name mask ccf_*.txt. Im use a ODIFileWait to start my process, but i cant get the file name to use in my interface. How i do to get the file name processed in the ODIFileWait?
    Thanks

    I have the same problem...

  • How can I get file name using JSTL ?

    Hi,
    I'm now using <c:out value="${pageContext.request.requestURI}"/>
    this return servlet path
    How can I get just file name
    or user path (in location bar) ?
    thanks in advance

    The original uri (before forwarding) is available in a request scoped attribute.
    These attributes are given the values obtained by calling the related method on the original request received by the container.
    javax.servlet.forward.request_uri
    javax.servlet.forward.context_path
    javax.servlet.forward.servlet_path
    javax.servlet.forward.path_info
    javax.servlet.forward.query_stringSo if those two above don't work for you these might.
    <c:out value="${requestScope['javax.servlet.forward.request_uri']}"/>
    <c:out value="${requestScope['javax.servlet.forward.servlet_path']}"/>If these values are null, then the value in the request object is the correct one.
    You mentioned the value in the address bar being a .html file. Do you perchance use framesets? If so the value in the address bar is always the url used to load the frameset, and doesn't change no matter where you travel within those frames. That won't be available to the server, because it has nothing to do with the current request.
    Cheers,
    evnafets

  • OS command to get file name

    Hello All,
    Using a single receiver communication channel I have to generate 2 output files.
    One output file name is OUTPUT.txt and the second output file name is OUTPUT<YYYYMMDD>.txt
    I am generating first output file name using standard file name scheme.
    And for generating second output file name I am using Run OS command option.
    can some one tell me the OS command to get the file name OUTPUT<YYYYMMDD>.txt?
    Thanx,
    Regards,
    Moorthy

    We would really like like to know how you are going to create 2 file (with different names) using same CC.
    If you are going to use "Add timestamp" then both the files will have timestamp at the end (unlike your requirement for the first file).
    I think its better to create 2 CC ..first with output.txt and the other OUTPUT<YYYYMMDD>.txt
    Also, please tell us more about ur requirment..if the content is same then..u can simply use a CC and use OS command (after processing option ) to copy it to the other location with required file name (OUTPUT<YYYYMMDD>.txt)
    Something like this  if u r using unix system and both the files are at same location:
    cp OUTPUT.txt OUTPUT2.txt

  • Query to get file name of field

    Hi folks,
    I have one field in SQL table with whole file names:
    e.g
    C:\Directory1\File 1.txt
    C:\Drirectory2\SubDirectory1\Image 33.jpg
    I need one query to show only the file names:
    e.g
    File 1.txt
    Image 33.jpg 
    What I need to do to get only the file names as result of query? 

    create table test (filenames varchar(100))
    insert into test values ('C:\Directory1\File 1.txt'),('C:\Drirectory2\SubDirectory1\Image 33.jpg'),('aaa'),(null)
    select Reverse(stuff(reverse(filenames)
    , Case when Charindex('\',reverse(filenames))>0 then Charindex('\',reverse(filenames)) else len(filenames) end
    , Case when Charindex('\',reverse(filenames))>0 then len(filenames) else 0 End
    ,'')) fileCol from test
    --Or
    SELECT Distinct Coalesce(S.a.value('(/H/r)[4]', 'VARCHAR(100)'), S.a.value('(/H/r)[3]', 'VARCHAR(100)'), S.a.value('(/H/r)[2]', 'VARCHAR(100)'), S.a.value('(/H/r)[1]', 'VARCHAR(100)') ) AS fileCol
    FROM
    SELECT *,CAST (N'<H><r>' + REPLACE(filenames, '\', '</r><r>') + '</r></H>' AS XML) AS [vals]
    FROM test) d
    CROSS APPLY d.[vals].nodes('/H/r') S(a)
    drop table test

  • B2B 11g: Getting File Name in inbound integration and passing it to SOA

    Hi,
    I am Reading a EDI x12 file in inbound B2B .I am checking the 'preserve File Name' check Box at Listening channel properties.....Then Integrating B2B to soa using AQ Adapter.But I couldn't find any property where I can pass the file name which I read through B2b to Composite. I need the file name because I am inserting all the records in Database and client wants to see which record in DB has been inserted from which file.
    Any pointers would be helpful.

    Hello,
    Try to use the b2b.fileName property. Although it probably is not shown on the list you should be able to access it.
    Also, please check the patch 18021286 which has many improvements and allows for two cases that can be useful for you:
    - Get information on back-end about which channel and agreement was used to deliver
    - Using callout Ret values which allow for specific properties to be set on callouts and passed all the way until the back-end application.
    Hope this helps.
    Best Regards
    Tiago Teixeira

  • How to get File name in Proxy program

    Hi,
    According to my business scenario, one XML file name comes from Legacy system and stores in a predefined directory. Now XI has to pick up that XML file and needs to call BAPI's which in turn updates the Target system ( SAP Tables).
    Now my problem is , XML File name is a combination of three fileds those are DATE , OBJECTKEY AND WORKFLOWNAME.
    Ex : YYYYMMDD_1234565789_WORKFLOWNAME.XML
         DATE_OBJECTKEY_WORKFLOWNAME.XML
    In proxy i need to get the file name and split into three fields ( those are DATE , OBJECTKEY AND WORKFLOWNAME ) which needs to send as import parameters in BAPI's.
    So please let me know from anyone in this group how to get the file name in the proxy program.
    Thanks & Regards
    K. naveen Kumar

    Hi,
    have a look at my new weblog:
    /people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14
    to see how you can access filename
    Regards,
    michal

  • Getting File Name in Automator workflow - combine PDF

    I am using Automator to combine 2 PDF files.
    I would like to inherit one of the file names in the new PDF and append a standard text to the front of the file name.
    I am not sure how to do this. I can combine the PDFs the way I would like, but I am not sure how to plick the file name.
    my workflow is as follows.
    Folder Action targets folder where 1st PDF is added(I want this FILE NAME).
    Ger Specified finder item selects 2nd PDF to be combined.
    Sort Finder Items makes sure the new PDF pages are ordered properly.
    Combine PDF Pages combines the pages.
    Move Finder Items saves the files where i want it.
    Name single item is whre i thought to add my standard text plus the variable of FILE NAME.
    Open File in mail to set up my email.
    Anyone can help with this?
    thanks,
    Aaron

    Here is an automator workflow that does something similar so I believe you can adapt to your needs.  This workflow is setup as a service workflow. It will combine PDFs in the order in which they are selected/clicked via the Shift key.  The default name of the combined output file will be the name of the first file clicked.  Automator can be activated by CTRL clicking any of the selected PDFs.
    1. Service receives PDF files in Finder
    2. Automator Action: Run AppleScript
    on run {input, parameters}
              display dialog "Files will be combined in the order selected via the Shift key" as text
              return input
    end run
    3.. Automator Action: Trim input items
    keep the first one
    you will need to download and install this autotmator action from here:
    http://www.menace-enterprises.com/Files/Automator/Actions/Trim%20Input%20Items.d mg
    4.  Automator Action: Run AppleScript
    (* Note & Definitions
    This Applescript extracts the basename of the first selected file without its .pdf extension
    "path_basename_ext" is full path and name, e.g. User/desktop/file.pdf
    "NmExt" is filename with extension, e.g. file.pdf
    "baseName" is the base filename without extension, e.g. file
    "Ext" is the file's extension, e.g. pdf
    on run {input, parameters}
              set path_basename_ext to input
              tell (info for path_basename_ext) to set {NmExt, Ext} to {name, name extension}
              set baseName to text 1 thru ((get offset of "." & Ext in NmExt) - 1) of NmExt
      baseName
              return baseName
    end run
    5.  Automator Action: Set Value of Variable
    define baseName as the variable
    6.  Automator Action: Get selected finder items
    Options: check ignore input
    7. Automator Action: Combine PDF pages
    choose Combine by appending
    8. Automator Action: Move Finder Items
    choose To: Desktop
    Options: check show this action when workflow runs
    9. Name Single Items
    choose Basename only to: baseName
    Options: check show this action when workflow runs
    10. Open Finder Items

  • Get File name of the inbound file during mapping

    Scenario: to read the file name of the inbound file (which has date required for the mapping) during runtime.
    The requirement is to read the date of the inbound file (passed to the XI pipline by the file adapter) and populate the same in the outbound mapping structure.
    Any idea about how to do this?
    (I went through few options of using java.util.map. not successful yet)

    Hi Anand,
    I posted the same question a time ago, without any help....
    Can I find out the full filename of input file in message mapping?
    Posted: Nov 23, 2004 1:00 PM
    I have in XI 2.0 the following scenario :
    In the inbound fileadapter I read my input file. The filename of the input file is part fixed, part variable (Like INDATA01.txt, INDATA03.txt, etc).
    So in my Adapterconfiguration, I specify the filename with a wildcard (INDATA*.txt).
    What I now want to do, is in my Message Mapping use the full filename , so I can do something different for every filenumber. Is there a way where I can get the full filename available in my message mapping (I did not find the filename in the XML in the message trace).

Maybe you are looking for

  • "Save attachments" button in Mail has disappeared

    My "Save attachments" button in Mail (6.6/1510) disappeared the other day. It has always been there, sitting on the dividing line between message header and message content. But now it's gone. All of a sudden. Sure, it becomes visible if I select det

  • Problem with a function

    Hi people, If someone made a call job in the SM35 I need your help! I use this two function to call a job, but when I debug the program in the SM35 transaction the JOB CLOSE function get the 'X' of processed in the variable that the function return b

  • SAP GRC ARQ: Modifying WF to fetch Organizational Owners (BRF+)

    D iDear all i have the following requirement regarding the ARM / ARQ process: 1.     have a user requestor who creates Access Request. They set the user id, the name, last name and the Organization (not the department, not the company,...) 2.     I w

  • Having trouble installing adobe reader x 10.1.4

    having trouble installing adobe reader x 10.1.4

  • ITunes refuses to Sync Audiobooks! :( HALP PLS.

    Hello, I posted this in the iPhone 4 section several days ago but got no response, so I'm hoping it'll get more attention in this sub-forum I've added an audiobook to my iTunes library and checked it off, but when I go to my iPhone 4's books section