Best way to copy/move files in Java...

I am trying to write or use Java to create directories on the filesystem, based on user information to a servlet. Using the File object and calling the mkdir() method, this works really well. I would like to add the functionality of then moving several files from an existing directory to this new one.
I can certainly write some code that uses the Runtime.getRuntime().exec("cp a.html b.html")and issue a system command, but if there's a better way, I'd appreciate it.
Thanks,
Jay

If you are implying that he use th renameTo() utility
of the File class, then that will only work when the
underlying system allows it - E.G., no renames across
mount points, hard drives, partitions, etc. Copy the
file yourself (with 7 or 8 lines of code) and avoid
the whole thing.I would be willing to accept these restrictions, but I never would have guessed that the renameTo() method would copy the file. That doesn't seem to make sense.
So you think I should just write code that issues a system command. I was hoping to avoid that because I dev and test on my Windows machine, then deploy to Unix. Is there nothing out there that handles file copies?

Similar Messages

  • Best Way to Copy Large Files

    In copying files to a USB memory stick, is there a particular file size limit above which simple drag and drop using the Finder does not work consistently? In general can we assume that if it appears to copy OK, then the files are in good shape? For example, if I'm copying a Documents folder with 5 GB of data onto an 8 GB USB stick would it be appropriate to use drag and drop? What are the alternative ways to copy large blocks of data? Is there a way to use Disk Utility for this?
    I should mention one of the reasons I'm asking. I've occasionally noticed large copying procedures sometimes cause the Finder to "hang."
    I do have SuperDuper which I use to clone my internal HD to a peripheral HD on a regular basis. Would that software provide a way to copy single files or folders containing lots of files to my USB memory stick?
    Thanks,
    Steve M.
    Message was edited by: Steve M.

    Drag and drop is fine. There's really no good reason to do it a different way.
    The only file limit is if the USB stick is formatted FAT32. Then 4GB minus 1 byte is the largest file size it can hold. If you format the stick as Mac OS Extended (HFS+), there's no limit to the file size, just the capacity of the drive itself.
    If you need to share between Mac and Windows, then formatting the stick as ExFAT is best. The only catch is that versions of OS X earlier than Snow Leopard will not be able to read the drive. Windows XP, Vista and Win 7 can read ExFAT. There is also essentially no file size limit with ExFAT.
    As far as the hanging, that may be the OS stalling on a file larger than 4 GB if the USB stick is formatted as FAT32.

  • Best way to convert .mov files to .avi???

    Hi, I'm getting kind of desperate here. I've been trying to export .mov files in compressor as .avi files. The video is coming out the same quality and is working fine but the audio is totally out of sync from the beginning, even though the clips are about 30sec long each.
    So, whats the best method to converting .mov files to .avi? I also tried using quicktime itself, (using the export menu). The exported material looks choppy though and won't play right. This may be because the footage is HD, 1080p shot on a JVC camera that recorded straight onto a memory card as .mov files.

    Okay, I have the files already in .mov as I was saying. So, I'm trying to convert them for my actress' editor (who requested them in AVI) because he uses Adobe Premiere Pro on a Windows Platform. I'm not sure which Premiere Pro version he has, nor do I know which formats it accepts as a result.
    You really know how to make things difficult. This adds a whole new set of questions. According to Adobe, if using v3.2.0 or later, there is direct support for XDCAM EX content stored to an SxS card which is not dependent on the "wrapper" (MOV or AVI in this case). So the fist question is what Premier Pro version is she using. Adobe also keeps referring to this content as "Sony XDCAM EX" content which makes me wonder if they are only supporting XDCAM EX content stored on a Sony manufactured camcorder or if the support is generic for any XDCAM EX camcorder manufacturer using the format, which was of course, "developed" by Sony. If the latter, then the next question becomes can the SxS content be be "imaged" for import/capture using Premier Pro's SxS built-in camcorder/card reader routine. If it can be imaged, then, as a non-Windows user, I simply do not know the best method for doing so. If it can't be imaged, would you be willing/able to send her the SxS card itself (or a cloned copy thereof) for her use. On the other hand, if she is using an older version of Premier Pro that does not support native XDCAM EX/Linear PCM editing, you need to ask her what specific compression formats she needs to be wrapped in her requested AVI file container. Until you know more/answer these questions, you cannot proceed further.
    I also tried using Mpeg Streamclip to convert the files to a AVI with a divx compression. Some worked, but most of them would get to 85% or 95% then drop off and say "compression error"... (settings were: quality 100%, frame rate 23.97 (what the video is), frame size 1280 x 720, Upper field dominance) ... I thought I put everything there right... SO what is happening is that about 85% of the clip will be there just fine, but then, all of a sudden, the video in the last few seconds will freeze on a frame and audio will be the only thing playing.
    Since you did not supply complete specific settings, it is difficult to tell for sure. For instance, if your target video data rate is set too low for the HD content, then at the 85-95% point the application may determine that it is impossible to achieve the target average data rate and stop compressing changes in the video scenes and you end up with either a frozen frame or a black screen. Have had this happen to with other encodes using MPEG-4/AVC. Basically the codec is simply reducing the current instantaneous video rate in an attempt to achieve the targeted "average" data rate by the time the end of the file is reached and the current date rate is simply too low to display more than a black screen or a picture in motion.
    Is it usually this difficult to convert formats like this? I thought it would be a quick fix, but it seems I'm running into a bunch of different problems.
    No, but then in a normal work for you would already know what format the editor actually wants to use for editing. As I indicated previously, it is unclear at this time whether she wants to edit content in the "native" format in Premier Pro or needs to have you convert the content to a different editing compression format. iMovie '09, for instance would normally use AIC (Apple Intermediate Codec)/AIFF (Linear PCM) for editing HD content.

  • What the best way to create XML files from JAVA application?

    Hi to all,
    I need to edit and to create new filex in format of xml. I know to parse, but what would be the best way to do:
    1. - Create new file, create like simle text file, or there is some clases that know to do it in more simple way
    2.a - Edit XML file, to take some data and add it to the XML in the place I want to.
    2.b - Also Edit, but not to add fields, just update some of them.
    Code examples or links to samples woul be welcomed.
    Best regards, Nick.

    I have tried working with XML directly using the Java classes but this was a pain. I then looked at DOM4J and JDOM and found JDOM easier to use.

  • Best way to copy large files to a desktop computer

    I have a MacBook Air with a large (16GB) iPhoto library that I want to copy to 2 desktop iMacs. The desktops are on an ethernet link with a hub, and I have an Airport network as well. Copy time via Airport shows as 20 hours. I have used the USB-to-ethernet connector to tie the MBA into the ethernet network but am still getting a copy time of 10 hours. Is there a faster way to link these machines? Thanks.

    I have found the fastest way is to copy the whole shebang on an external hard disk with a USB 2 connection. I also have tons of photographs on mine and make that step in between e.g. first copy on an external HD and then on to the larger Mac
    what you describe is terribly slow. I agree

  • What is the best way to copy aperture library on to external hard drive? I am getting a message that say's "There was an error opening the database. The library could not be opened because the file system of the library's volume is unsupported".

    What is the best way to copy aperture library on to external hard drive? I am getting a message that say's "There was an error opening the database. The library could not be opened because the file system of the library's volume is unsupported". What does that mean? I am trying to drag libraries (with metadata) to external HD...wondering what the best way to do that is?

    Kirby Krieger wrote:
    Hi Shane.  Not much in the way of thoughts - - but fwiw:
    How is the drive attached?
    Can you open large files on the drive with other programs?
    Are you running any drive compression or acceleration programs (some drives arrive with these installed)?
    Can you reformat the drive and try again?
    Hi Kirby,
    I attached the UltraMax Plus with a USB cable. The UltraMax powers the cable so power is not an issue. I can open other files. Also, there is 500GB of files on the drive so I cannot re-format it. Although, I noted I could import the entire Aperture Library. However, I do not want to create a duplicate on my machine because that would be defeating the purpose of the external drive.
    Thanks,
    Shane

  • I have a iMac Desktop and MacBook Pro laptop. I generate my work related files on both of these machines. What is the best way to keep the files in these machines synchronized?

    I have a iMac Desktop and MacBook Pro laptop. I generate my work related files on both of these machines. After a few days or weeks, I have new files on some folders on either of the machines that is not on the other machine. What is the best way to keep the files in these machines synchronized?

    How did you transfer the files to the iMac.  If you exported the files out of the MB library using Kind = Current you should get the edited version.  Any other  option may not.
    If you want to keep the two libraries "synced"  any photos you want to move to the iMac should be added to an album, connect the two Mac with a LAN, Target Disk Mode,  Transferring files between two computers using FireWire, with WiFi. and use the paid version of  iPhoto Library Manager to copy that album from the MB library to iMac library.  It will also copy the original and edited versions, keywords, titles, etc.
    OT

  • Best way to copy range of paragraphs

    I'm getting all the changebars in the files of a book, and copying them out into a separate, single change document. Once I find the Pgf with the changebar, what would be the best way to copy the info out to the change doc? I want to copy the entire section that contains the changebar.
    I figured I would move backwards and find the most recent section heading and set the beginning of a TextRange there at the beginning of that Pgf. Then I move forward and find the following heading pagagraph, and move back one pgf from that and set that as the end of the range.
    At that point should I use copy and paste into the new document?
    Thanks, Mark

    Hi Mark,
    Glad you are making progress. About the Pgfs in tables: yes, they are in a world of their own. Each table is a more or less closed object anchored to a paragraph in the document. You can step through all Pgfs in a document (including the ones in your text flows as well as the ones in table cells) using one single linked list, but that list does not care about the order in which the paragraphs appear in your document, and also includes paragraphs on your master and reference pages. This is not what you want to have.
    You mentioned you wanted to copy not just the paragraph with changebars but the section that contains at least one paragraph with changebars. One strategy is finding a paragraph with changebars and then tracking back to the previous heading and forward to the next heading, so that you can determine which section to copy to your changes document. With the requirement of checking paragraphs in tables added into the equation, this becomes a complex matter. Even if you know that a paragraph in a table cell has a changebar set, you should track back to the table anchor, then to the paragraph in which the anchor is located, and then back to the section that you need to copy. And if the section also contains a paragraph with changebars outside a table, you do not want to copy it again.
    This might require a completely different approach to the problem. Build an array with paragraph identifiers of all headings in your document, and create an array of booleans all set to false that has the same number of entries. Then find all paragraphs with changebars and, for each found paragraph, walk back to the nearest heading, find the heading identifier in the headings array and set the corresponding entry in the boolean array to true. Then do the same thing with paragraphs with changebars in tables. In this case, you track the paragraph in the table back to its table anchor, then to the paragraph containing the table anchor and from there walk back to the nearest heading.
    In the end you will have an array of heading paragraph identifiers and a matching array of booleans telling you which sections to copy to the changes document. Doing the copying is dead easy, as you already have the start and end paragraph identifier for each section. Just create a TextLoc pointing at the first heading Pgf with offset 0 and a TextLoc pointing at the next heading Pgf with offset 0 and copy this range.
    I hope this makes sense to you. If things get too complicated, throw me an email (you will find my mail address in my profile) with a sample file and I will have a look at it. If I think it will take me more than a couple of hours to write, I will make you a decent offer.
    Kind regards
    Jang

  • Copy/move file on application server

    Hey guys,
    is there an easy way to copy/move a file from one directory on application server to an other directory? I know i could use the commands OPEN DATASET and so on. Is there an other way to do this via a function module?
       thx,
         M.
    Moderator Message: Please search before posting, this has been discussed many times in the forum. All points unassigned
    Edited by: Suhas Saha on Aug 13, 2011 10:28 PM

    Hi ,
    As you know about the open dataset way of doing this ...You need another way and that will be as mentioned in the link below .....
    [Copy one file to another on application server |Re: Move  file from one folder to another floder in application server;
    Hope it helps ....
    Thanks,
    Anjaneya
    Edited by: Anjaneya Bhardwaj on Aug 13, 2011 1:02 PM

  • Best way to handle text files in OD10g

    We have a requirement to store reports in text format into a database field, to be able to view the reports, and to print them if desired using Forms 10g. What is the best way to handle this?
    - define the field in the database as clob or blob?
    - if CLOB is the choice, what tools to use to upload CLOBs to the database (since webutil transfer is for blob only)?
    - in Forms 10g, can one use the Forms data type LONG for CLOB?
    - can you do Forms search on clob and blob fields?
    - how can reports that are stored in fields be viewed without first downloading to the client workstation?
    - in Forms 10g, what is the best way to view text files residing in local PCs: "host notepad myFile"?
    Thanks much for your reply!
    gk

    Take a deep breath. Relax. All is fine.
    iDVD does not look at the size of your video file, it looks at the length. iDVD can accomodate up to 2 hours of movie
    iDVD gives you different options depending on the length of your movie. Although I won't agree with your friend about reducing the length of your movie to 15 minutes, if you could trim out a few minutes to get it under an hour that setting in iDVD (Best Performance though the new version may have renamed it) gives you the best quality. Still, any iDVD setting will give you good quality even at 64 minutes
    In FCE export as Quicktime Movie NOT any flavour of Quicktime Conversion. Select chapter markers if you have them. If everything is on one system unchecked the Make Movie Self Contained button. Drop the QT file into iDVD

  • I'm buying a new Macbook Pro this week and am wondering what is the best way to copy over the software I have from my existing Macbook Pro to the new one? eg. Photoshop and Office etc. I no longer have the CDs.

    I'm buying a new Macbook Pro this week and am wondering what is the best way to copy over the software I have from my existing Macbook Pro to the new one? eg. Photoshop and Office etc. I no longer have the CDs.

    Ya know what I'm on a brand new MBP just about 24 hours old and you know whats been working amazingly for me. I have a 27inch iMac as well and i've just connected it to my network and been dragging files and apps across the network onto my new MBP. Its really working fast and its flawless. You could always do that option, Just go into sharing options and turn them on for both Macs. Then just click and drag. Of course they have to both be on the same network for this to be possible.
    Look at my network.
    Shared is what your looking at.  I click on there see all my computers files and then drag the ones i want form its folder to my MBP folders.  Hope that helps if your looking for a very simple way on a wireless network.

  • What is the best way to find a file on the servers disk without using web.xml?

              What is the best way to find a file on the servers disk without using web.xml?
              I want to find a configuration file not contained within the war file I have
              created. Is there a way to pass information into the ServletContext with out
              rebuilding the ear or war files? Tomcat 4.0 can do this in its server configuration
              files. Does BEA have the equivalent?
              Regards,
              Eric
              

    You can specify the path to the file as a system property
              eg
              java -Dconfig.file.location=./mydirecotry/myfile.txt com.test.MyApp
              "Eric White" <[email protected]> wrote in message
              news:[email protected]..
              >
              > What is the best way to find a file on the servers disk without using
              web.xml?
              > I want to find a configuration file not contained within the war file I
              have
              > created. Is there a way to pass information into the ServletContext with
              out
              > rebuilding the ear or war files? Tomcat 4.0 can do this in its server
              configuration
              > files. Does BEA have the equivalent?
              >
              > Regards,
              > Eric
              

  • Best way to handle source files

    Hi there,
    After some pretty general advise please.
    The company I work for looks after a lot of websites, and one
    of the
    headaches we have is the best way to handle source files. By
    source files I'm
    referring to Photoshop files, Flash .fla files and also other
    none Adobe
    files that relate to a site, not the .html, .asp, .aspx,
    .css, .js etc type
    files.
    Now I'm NOT after a version control system, just a simple way
    to store the
    source files in a location that is separate from the website
    but still to be
    able to have a smooth workflow between the Dreamweaver site
    and it's source
    files.
    At the moment, and I know this is unwise, we have a
    subdirectory within the
    site where we store the source files, and use WebDAV to
    transfer both site
    and source files to and from the server. But I really want to
    separate the
    site from source but still maintain a link between site and
    source...... if
    you see what I mean. I think the upshot is I would like to be
    able to open a
    site within Dreamweaver and instantly be able to access that
    sites source
    files if needed. This method needs to be shared across a
    small team spread
    round the UK.
    I looked at the Repository Subversion version control, but
    like I said I'm
    not after a source control system, plus it appeared to
    conflict with WebDAV
    and Contribute, that some of our clients use to maintain
    content on their
    sites. I also looked at Version Cue which looked promising,
    but can't see a
    clear workflow between Dreamweaver and Version Cue which
    separates site from
    source. I might be missing something.... part of my brain
    perhaps. :)
    Would be grateful for any advice please.
    Cheers,
    @ndyB

    Take a deep breath. Relax. All is fine.
    iDVD does not look at the size of your video file, it looks at the length. iDVD can accomodate up to 2 hours of movie
    iDVD gives you different options depending on the length of your movie. Although I won't agree with your friend about reducing the length of your movie to 15 minutes, if you could trim out a few minutes to get it under an hour that setting in iDVD (Best Performance though the new version may have renamed it) gives you the best quality. Still, any iDVD setting will give you good quality even at 64 minutes
    In FCE export as Quicktime Movie NOT any flavour of Quicktime Conversion. Select chapter markers if you have them. If everything is on one system unchecked the Make Movie Self Contained button. Drop the QT file into iDVD

  • What is the best way to copy data....

    Hello friends,
    What could you think is the best way to copy this data ? :
    - I have two identical databases (Oracle 9i)
    - I want to migrate the data of 90 tables (all tables begin with the same string, i.e. 'TAB') from Database1 to database2.
    - There are integrity constraints, referentials, etc.
    I'd like to generate a script to automate/accelerate the process.
    So, I'm thinking on the following:
    - Disable all the constraints in Database2.
    - Connect to Database 1 and generate a script with the 'inserts' using TOAD (or another similar application)
    - In a Database 2 session, execute the script...
    Of course if I use TOAD I can't generate an unique script to do this process in one step so...
    Any better idea? (Using export/import, ... or some script you have...)
    Thanks.
    Jose.

    Use exp and imp. It works... seriously! And you don't need to drop the user/schema. But don't take my word, run an example...
    On Database 1
    First let's create a couple of tables with referential integrity to each other to make sure exp/imp can handle it...
    SQL> create table t1 (t1_id number constraint pk_t1 primary key, t2_id number);
    Table created.
    SQL> create table t2 (t2_id number constraint pk_t2 primary key, t1_id number);
    Table created.
    SQL> alter table t1 add constraint fk_t1_t2 foreign key (t2_id) references t2 (t2_id);
    Table altered.
    SQL> alter table t2 add constraint fk_t2_t1 foreign key (t1_id) references t1 (t1_id);
    Table altered.
    SQL> insert into t1 (t1_id, t2_id) values (1, null);
    1 row created.
    SQL> insert into t2 (t2_id, t1_id) values (2, 1);
    1 row created.
    SQL> update t1 set t2_id = 2 where t2_id is null;
    1 row updated.
    SQL> commit;
    Commit complete.
    SQL> select * from t1;
         T1_ID      T2_ID
             1          2
    SQL> select * from t2;
         T2_ID      T1_ID
             2          1
    SQL> select table_name, constraint_name, constraint_type, r_constraint_name from user_constraints
      2  where table_name in ('T1','T2');
    TABLE_NAME                     CONSTRAINT_NAME                C R_CONSTRAINT_NAME
    T1                             PK_T1                          P
    T1                             FK_T1_T2                       R PK_T2
    T2                             PK_T2                          P
    T2                             FK_T2_T1                       R PK_T1
    SQL>
    Now let's export those tables. You can build a parfile manually or even spool it from a sql script with the names of all tables you need to export...
    $ cat parfile.txt
    tables=(\
    t1,\
    t2
    $ exp rc/pwd parfile=parfile.txt file=db1.dmp log=db1.log
    Export: Release 10.1.0.3.0 - Production on Mon Jan 9 20:49:17 2006
    Copyright (c) 1982, 2004, Oracle.  All rights reserved.
    Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production
    With the Partitioning, OLAP and Data Mining options
    Export done in UTF8 character set and UTF8 NCHAR character set
    About to export specified tables via Conventional Path ...
    . . exporting table                             T1          1 rows exported
    . . exporting table                             T2          1 rows exported
    Export terminated successfully without warnings.
    On Database 2
    Copy your .dmp file to Database 2
    Import
    $ imp rc/pwd full=y file=db1.dmp log=db1_imp.log
    Import: Release 10.1.0.3.0 - Production on Mon Jan 9 20:51:15 2006
    Copyright (c) 1982, 2004, Oracle.  All rights reserved.
    Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production
    With the Partitioning, OLAP and Data Mining options
    Export file created by EXPORT:V10.01.00 via conventional path
    import done in UTF8 character set and UTF8 NCHAR character set
    . importing RC's objects into RC
    . . importing table                           "T1"          1 rows imported
    . . importing table                           "T2"          1 rows imported
    About to enable constraints...
    Import terminated successfully without warnings.
    All data is there...
    SQL> select * from t1;
         T1_ID      T2_ID
             1          2
    SQL> select * from t2;
         T2_ID      T1_ID
             2          1 All constraints are there...
    SQL> select table_name, constraint_name, constraint_type, r_constraint_name from user_constraints
      2  where table_name in ('T1','T2');
    TABLE_NAME                     CONSTRAINT_NAME                C R_CONSTRAINT_NAME
    T1                             PK_T1                          P
    T1                             FK_T1_T2                       R PK_T2
    T2                             PK_T2                          P
    T2                             FK_T2_T1                       R PK_T1It does work!

  • How do I copy/move files?

    What class do I use to copy/move files? I looked in java.io.file but I didn't see anything appropriate.

    Thanks for the point about NT and AIX. The exact reason I'm looking at this is to develop a stored procedure in an Oracle DB which will assist with backup operations on both NT and AIX. Thus whatever I do needs to work both places. We already have OS specific scripts that I'd like to get rid of . . .

Maybe you are looking for

  • How to pass the values from popup window to parent's window

    Hi Experts, in my application i need to develop one popup window in that i have created 4 dropdowns and one ok button , if i willl click on that ok  button the values should pass to parent window dropdownlistboxes can any body suggest how i will get

  • Disabling User specific/Default Setting

    In the output of CV04n selection while 'Save Layout' how is it possible to enable/disable 'User Specific' or 'Default setting'

  • CreateNewDialog of dialog manager with caching option True cause ID CS6 crash on quit in windows

    following line of code cause crash on some windows machine when i quit indesign (even without doing anything) but if last option (caching) replace with kFalse there is no crash on any machine .there is no crash on Mac in either case. IDialog* dialog

  • Jurisdiction code error message in MIRO

    Hi, I have hidden a field "Smart Number" in all the layouts available in MIRO transaction as this field was not wanted in MIRO. Now I am trying to post an invoice verification for a scheduling agreement using the screen layout "9_6310 Purchase Order

  • TRANSPORT OF BIN STRUCTURE

    Hello all, I would like to know whether the bin structure created using LS10 can be transported from a development server to the next server or is it independent of transport and cannot be transported. pl. advise Thanks, Maxx