Skip to Content
avatar image
Former Member

Read a file from the local system

Hi,

Is it possible to read a file from the local system? If yes, how?

Please forward your suggestion..

Thanks,

RPN

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Dec 01, 2008 at 07:26 AM

    this is the sample code to write file on local machine...using UI element

    write this code on the action of UI elemenet.

    PS: Use outputStream for reading the file

    public void onActionUploadFile(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

    {

    //@@begin onActionUploadFile(ServerEvent)

    String FileName = "temp";//wdContext.currentContextElement().getDirectory();

    InputStream input = null;

    int i=0;

    FileIncreament();

    try {

    String directory =".
    temp
    webdynpro
    web
    local
    yh1245_ftp"+

    "
    Components
    com.yash.yh1245.Upload
    "FileNamewdContext.currentContextElement().getCounter();

    boolean sucsss = new File(directory).mkdir();

    if(sucsss){

    wdComponentAPI.getMessageManager().reportSuccess("Directory Created ");

    File file = new File(directory"
    "
    wdContext.currentContextElement().getResourceURL().getResourceName().toString());

    FileOutputStream fos = new FileOutputStream(file);

    wdComponentAPI.getMessageManager().reportSuccess(file.getAbsolutePath());

    FilePath = file.getAbsolutePath();

    if(wdContext.currentContextElement().getResourceURL()!=null){

    input = wdContext.currentContextElement().getResourceURL().read(false);

    //wdComponentAPI.getMessageManager().reportSuccess("Resource is not null ");

    while((i = input.read())!=-1){

    fos.write(i);

    }

    }

    fos.flush();

    fos.close();

    wdComponentAPI.getMessageManager().reportSuccess("File Uploaded on server directory ");

    //wdComponentAPI.getMessageManager().reportSuccess("Created File Locaiton::"+file.getAbsolutePath());

    //}

    //Get the File Size

    // IPrivateFTPUpload.IContextElement element = wdContext.currentContextElement();

    // if (element.getResourceURL()!=null) {

    // IWDResource resource = element.getResourceURL();

    // element.getFileSize(this.getFileSize(resource));

    // }

    }

    }catch(Exception e){

    e.printStackTrace();

    }

    //@@end

    }

    Add comment
    10|10000 characters needed characters exceeded