Java - Copy files on a network share

Posted on 2012-08-29
Last Modified: 2012-09-04
I have written an application that needs to place an xml file on a network share.  I am comfortable with, and have written the code to generate the file h. However, I have not found a good method of writing that file to a network share.  What I would like to do is take the file on the network share, rename it and over write the original every day.  In my research I have found many options like socket programming, ipc channels etc...  What would be best, does anyone have a code sample at which I could look? What would I need to address in the form of permissions?

Any help would be greatly appreciated.
Question by:shanemay
    LVL 86

    Expert Comment

    File shared = new File("\\\\hostname\\sharename\\filename.xml")); // Now open a stream on 'shared'

    Open in new window

    The above assumes Windows. Let me know if that's not the case
    LVL 9

    Accepted Solution


    Author Closing Comment

    Thank you, that is what I am needing.
    LVL 86

    Expert Comment

    Why would you need jcifs for that?

    Author Comment

    Because I need to copy / move files. Also, I have to deal with file share permissions, etc... If there is a better way to handle the file, I would be more than happy to look at it.  

    Thank you for your help.
    LVL 86

    Expert Comment

    What I would like to do is take the file on the network share, rename it and over write the original every day.  

    was what i thought was your use case. The code i gave you will do that. If that's not your use case, then it could be that jcifs is necessary

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    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 will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    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:

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now