I am a beginer.please help me.thanks.

//The source code is listed below,and questions are also listed.Thanks for reading.
import java.io.*;
public class copyfile{
static public int main(String[] argv){
String srcfile=new String("test.txt");
String destfile=new String("test.backup");
File src=new File(srcfile);
boolean existe=src.exists();
if(!existe){
System.out.println("file "+src.getName()+" is not existe.Please create one first and try again.");
//throws new FileNotFoundException;
//why the above statement is wrong??
System.exit(1);
//boolean create=(File dest=new File(destfile)).createNewFile();
//What's wrong with the above statement???Why??!
File dest=new File(destfile);
try{
boolean create=dest.createNewFile();
}catch(IOException e){
System.exit(1);
}finally{
if(create){
System.out.println("file "+dest.getName()+" was created!");
}else{
System.out.println("file "+dest.getName()+" was already existe.");
}//end_finally
try{
copy(src,dest);
}catch(IOException e){
System.out.println("Caught one io exception");
return 1;
static void copy(File src,File dest) throws IOException{
InputStream in=new FileInputStream(src);
OutputStream out=new FileOutputStream(dest);
byte[] buf=new byte[1024];
int len=0;
while((len=in.read(buf))>0)
out.write(buf,0,len);
in.close();
out.close();
}//end_copy
// by longwen

//The source code is listed below,and questions are also listed.Thanks for reading.
import java.io.*;
public class copyfile{
    static public int main(String[] argv){
       String srcfile=new String("test.txt");
       String destfile=new String("test.backup");
       File src=new File(srcfile);
      boolean existe=src.exists();
    if(!existe){
       System.out.println("file "+src.getName()+" is not existe.Please create one first and try again.");
         //throws new FileNotFoundException;
//why the above statement is wrong??
System.exit(1);
    //boolean create=(File dest=new File(destfile)).createNewFile();
//What's wrong with the above statement???Why??!
File dest=new File(destfile);
    try{
        boolean create=dest.createNewFile();
       }catch(IOException e){
               System.exit(1);
       }if(create){
           System.out.println("file "+dest.getName()+" was created!");
        }else{
            System.out.println("file "+dest.getName()+" was already existe.");
    try{
        copy(src,dest);
        }catch(IOException e){
            System.out.println("Caught one io exception");
          return 1;//why i cannot use System.exit(0);
   static void copy(File src,File dest) throws IOException{
                InputStream in=new FileInputStream(src);
               OutputStream out=new FileOutputStream(dest);
              byte[] buf=new byte[1024];
              int len=0;
       while((len=in.read(buf))>0)
             out.write(buf,0,len);
     in.close();
     out.close();
    }//end_copy
// by longwen

Similar Messages

  • My email only shows the "to" and "from" info but not the content of the email. Please help. Thanks

    My email only shows the "to" and "from" info. There is no information at all in the body of my email messages. Please help. Thanks.

    Close the mail app and reboot the iPad.
    Tap the home button once. Then tap the home button twice and the recents tray will appear at the bottom of the screen. Tap and hold down on any app icon until it begins to wiggle. Tap the minus sign in the upper left corner of the mail icon. Tap the home button twice.
    Reboot the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up.

  • I have frequent instances of my Macbook Pro beeping 3 times and then I have to forcefully shut it down by pressing the power button. What is this all about? Please help. Thank you.

    I have frequent instances of my Macbook Pro beeping 3 times and then I have to forcefully shut it down by pressing the power button. What is this all about? Please help. Thank you.
    I saw this report being sent to Apple:
    Interval Since Last Panic Report:  581719 sec
    Panics Since Last Report:          10
    Anonymous UUID: F4CF708D-D85C-4EC5-8047-4FC22C6B03AF
    Fri Mar  7 13:00:14 2014
    panic(cpu 0 caller 0xffffff80002d1208): Kernel trap at 0xffffff800020c590, type 14=page fault, registers:
    CR0: 0x0000000080010033, CR2: 0x0000000000000000, CR3: 0x0000000007541000, CR4: 0x0000000000040660
    RAX: 0xffffff8000000000, RBX: 0xffffff800d35a870, RCX: 0xffffff800cf55cd8, RDX: 0xffffff80008a8fcc
    RSP: 0xffffff805e5f3d60, RBP: 0xffffff805e5f3da0, RSI: 0x000000001dcd6500, RDI: 0xffffff800d168778
    R8: 0x0000000000000001, R9: 0xffffff805e5f3e88, R10: 0x0000000000000011, R11: 0x0000000000000000
    R12: 0x0000000000000000, R13: 0xffffff800d168770, R14: 0xffffff800d168778, R15: 0x0000000000000000
    RFL: 0x0000000000010082, RIP: 0xffffff800020c590, CS:  0x0000000000000008, SS:  0x0000000000000010
    Error code: 0x0000000000000000
    Backtrace (CPU 0), Frame : Return Address
    0xffffff805e5f3a00 : 0xffffff8000204d15
    0xffffff805e5f3b00 : 0xffffff80002d1208
    0xffffff805e5f3c50 :
    Model: MacBookPro8,1, BootROM MBP81.0047.B27, 2 processors, Intel Core i5, 2.3 GHz, 4 GB, SMC 1.68f99
    Graphics: Intel HD Graphics 3000, Intel HD Graphics 3000, Built-In, 384 MB
    Memory Module: global_name
    AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0xD6), Broadcom BCM43xx 1.0 5.100.198.104.5)
    Bluetooth: Version 2.4.5f3, 2 service, 12 devices, 1 incoming serial ports
    Serial ATA Device: Hitachi HTS545032B9A302, 298.09 GB
    Serial ATA Device: OPTIARC DVD RW AD-5970H
    USB Device: FaceTime HD Camera (Built-in), 0x05ac  (Apple Inc.), 0x8509, 0xfa200000 / 3
    USB Device: Hub, 0x0424 (SMSC), 0x2513, 0xfa100000 / 2
    USB Device: BRCM2070 Hub, 0x0a5c  (Broadcom Corp.), 0x4500, 0xfa110000 / 5
    USB Device: Bluetooth USB Host Controller, 0x05ac  (Apple Inc.), 0x821a, 0xfa113000 / 8
    USB Device: Apple Internal Keyboard / Trackpad, 0x05ac  (Apple Inc.), 0x0245, 0xfa120000 / 4
    USB Device: Hub, 0x0424 (SMSC), 0x2513, 0xfd100000 / 2
    USB Device: IR Receiver, 0x05ac  (Apple Inc.), 0x8242, 0xfd110000 / 3

    Hmm. The problem still may be the RAM - Apple buys the RAM it puts in its machines from third-party vendors (usually Hynix) so it could be a RAM problem.
    There are a couple of things that you can do yourself before taking your machine into an Apple Store or an AASP... download and run an application named Rember that will run a RAM test for you - let it run for a couple of hours or even overnight. If it turns out that your RAM is faulty, Rember will let you know. If it is faulty, then you have a couple of options - replace the RAM yourself or (particularly if you're under warranty still) take the machine to an Apple Store or AASP and have them replace the RAM.
    If Rember finds no fault with the RAM, then you'll need to take it into an Apple Store/AASP and get a free diagnosis on the machine. Three beeps do usually indicate faulty RAM, but if it tests good with Rember you likely have another problem - it could be something as simple as the RAM, somehow, not seated correctly or signs of another hardware problem.
    Run Rember first... call back with results.
    Good luck,
    Clinton

  • I have an iPhone 4s just eight months, it is normal that the battery lasts only 3 hours? please help me thank you very much.

    I have an iPhone 4s just eight months, it is normal that the battery lasts only 3 hours? please help me thank you very much.

    Three hours if definitely NOT normal. I get at least 48 hours out my 2 year old iPhone 4S' battery with light usage. Did you do the iOS 7 update on the phone it self (OTA) or through iTunes? In my experience most problems are caused by the OTA updates. For this reason I ALWAYS update using iTunes on my computer.
    I would suggest restoring your phone using iTunes on your computer and setting it us as a new phone. This downloads a fresh copy of iOS 7.1 from Apple and installs it on your phone. Just make sure that you transfer all purchased items (apps, music, etc.) as well as photos to your computer before restoring as the restore will completely wipe your phone. Do not restore from a back-up. Yes, you will loose all your data on the phone but restoring a back-up can restore the problem you are currently having back to your phone. Once your phone has been restored you can manually sync back your apps and music.
    Before restoring you can also check to see that battery-killers like Location Services, Background App Refresh, etc are only turned on for the apps that really need it. I recently read and article that said that the Facebook app can be a real battery killer. If you have this app installed turn of location services and background app refresh for this app and see if that helps. Also go to Settings / General / Restrictions / Location Services / System Services and turn off all the options in that menu. Your phone does not need any of those to function. Constantly using your phone's GPS is a huge battery killer. I only have Location Services enabled for Find my iPhone and Background App Refresh is turned off completely.
    I hope this helps.

  • I copied the photos from my photo stream folder to a new folder on my macbook pro. I then deleted the phots in my photo stream folder. It erased them from the other folder as well. Why? Where did they go? Can I get them back? Please help. Thanks.

    Hello, I wanted to clear out my photo stream folder on my macbook pro, so I copied all the photos to a permanent folder. I then deleted all the photos in my photo stream folder. The photos in my backup folder were automatically deleted and I want them retrieved. They are not in my trash and I can't find them. Are photos autmatically backed up in my phots? How can I retrieve the deleted photos? Please help. Thanks.

    You can't currently delete individual photos but you can reset
    Step 1: Login to your iCloud account on iCloud.com from a Mac or PC.
    Step 2: Click on your name at the top right of the main iCloud page.
    Step 3: Click on the Advanced option.
    Step 4: Click “Reset Photo Stream.” You will then need to confirm.
    Step 5: This Photo Stream reset will not go into effect until you toggle Photo Stream on and off on your devices. In iOS, Photo Stream can be turned off and on in the iCloud settings window of the Settings app.

  • Hi i am having a lot of trouble getting my pictures from my ipod 4 to download to my laptop! I just cant figure it out! please help! thanks!

    I cant't get my pictures from my ipod touch 4 to my laptop!!!! Please help me thank you!!!!!

    iOS: Importing personal photos and videos from iOS devices to your computer

  • HT204053 I have two Apple ID's. How do I delete one of them? Please help. Thank you. Dru

    I have two Apple ID's. How do I delete one of them? Please help. Thank you. Dru

    To add to the above...
    From Here   http://support.apple.com/kb/HE37
    I have multiple Apple IDs. Is there a way for me to merge them into a single Apple ID?
    Apple IDs cannot be merged. You should use your preferred Apple ID from now on, but you can still access your purchased items such as music, movies, or software using your other Apple IDs.

  • How can I sync my photo contents in iPhoto on my iMac to my new iPAD's iPhoto?  I follwed all the instructions on manuals for both iPAD and iTunes re syncing, but I cannot find "phone button" under Device name on iTunes page. Please help!  Thanks!

    I follwed all the instructions on manuals for both iPAD and iTunes re syncing, but after physically connecting iPAD with iMac with USB or via WiFi I still cannot find "phone button" under Device name on iTunes page. Please help!  Thanks!
    I have been creating a photo book using a lots of photographs on iPhoto, and then I took another photos by using new iPAD which I want to integrate with the original album/book on iMac. I was able to import them from iPAD's iPhoto to iMac's iPhoto.  However I cannot import or transfer or sync anything from iMac's iPhoto to that of my iPAD. 
    So my iPhoto page on iPAD contains only 3 or 4 newly created albums, and no other info.  That means no syncing....
    I am supposed to be able to work on this project on either of these iPAD and iMac, correct?
    I am puzzled.  I appreciate for your advice and help.
    Thank you!

    It doesn't appear under the iPad device on the left-hand sidebar of iTunes, you need to select the iPad device on the sidebar and then select the Photos tab on the right-hand side of iTunes e.g.
    And then on the right-hand side :

  • Hello Guys. I had problems in the Computer before and changed my HD. I saved in my all files documents in (Time Capsule). How can I put all my files, pictures documents on my new HD? Please Help. Thank You

    Hello Guys.
    I had problems in the Computer before and changed my HD. I saved in my all files documents in (Time Capsule). How can I put all my files, pictures documents on my new HD?
    Please Help.
    Thank You
    Julio Skov

    Hey
    Thank you very much for replay.
    Would you explain to me how can I do?
    I don't really understand these processes.
    Thak you very much
    Julio

  • Hi - I keep receiving the following error message on a song I purchased from itunes and am now trying to drag and drop to my iPad: "you must download items from icloud before you can copy then to iPad" what does this mean - please help! Thank you

    Hi - I keep receiving the following error message on a song I purchased from itunes and am now trying to drag and drop to my iPad: "you must download items from icloud before you can copy then to iPad" what does this mean - please help! Thank you

    Hi Poonam26c,
    If you do not have a local copy of a song which you have purchased (i.e. it is available via iTunes in the Cloud), you may need to redownload it before you can transfer it to your device. You may find the following article helpful:
    Apple Support: Downloading past purchases from the iTunes Store, App Store, and iBooks Store
    http://support.apple.com/kb/HT2519
    Regards,
    - Brenden

  • As a new MacBook user I plug in my USB Flash Drive but don't know how to access its contents. Please help. Thanks.

    as a new MacBook user, when inserting my USB Flash Drive, I do not know how to access its contents. Please help. Thanks.

    Open a new Finder window, Finder > File > New Finder Window, and it should appear on the left under Devices.
    If you don't see it there, or to get it to show up on the Desktop: Finder > Preferences... General tab, check External disks to have it show on the Desktop,  Or Sidebar tab, check External disks under DEVICES.

  • I down loaded about 100 cds to my library and I can no longer view the downloaded artwork it's shows a black picture or blank. How can I get the artwork back? Please help! Thank you

    I downloaded about 100 cds to my library and I can no longer view the downloaded artwork it's shows a black picture or blank. How can I get the artwork back? Please help! Thank you.

    Hi- apparently I also had a similar moment of madness and thought that 'freeride games' would be fun. Well, so much for that! It added a ton of things to my tool bar, I would like to uninstall it, any suggestions for this one?
    thanks :)

  • HT1335 My ipod classic have no software and I am stuck with it. It was formatted for apple but I use windows 8.  Please help. Thanks in advance.

    My ipod classic have no software and I am stuck with it. It was formatted for apple but I use windows 8.  Please help. Thanks in advance.

    Hello there, DrDhillon.
    The following Knowledge Base article goes over the steps that will help you resolve your issue:
    Restoring iPod to factory settings
    http://support.apple.com/kb/HT1339
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro.

  • I am having trouble dating to version 3.6.14. I am running Linux/Ubutu OS and I get this error message:/tmp/p7x3vko2.part could not be saved, because the source file could not be read. Please help. Thank you , Deb

    I am having trouble dating to version 3.6.14 or updating to the Beta testing. I am running Linux/Ubutu OS and I get this error message:/tmp/p7x3vko2.part could not be saved, because the source file could not be read. Please help. Thank you , Deb

    Solved for me.
    I set the owner/permissions of my profile's mozilla folder's (and all the files in it) to read/write access, and the problem disappeared.
    in linux:''
    * cd /home/myusername/.mozilla
    * chown -cR myusername:mygroup ./
    * chmod -cR +rw ./
    '''Never do that with root privs (nor with sudo)'''

  • Can't seem to download any app despite entering the correct password and answering 3 security question but still in the end it comes up the message that my session has timed out no matter what! Please help, many thanks in adv!!

    Can't seem to download any app despite entering the correct password and answering 3 security question but still in the end it comes up the message that my session has timed out no matter what! Please help, many thanks in adv!!

    Try doing it on your computer with iTunes and then sync to your iPad to see if it clears the problem.

Maybe you are looking for

  • How can I send more than one foto in a email

    How can I send more than one foto in a email?

  • To do's before and after upgrade

    On another post, I noted that I cleared my home screens prior to upgrading as was suggested on a droid life site.  The upgrade notification will be obvious and you get to choose between install now, or wait, or get more information.  I just held off

  • G5 wont boot past white Apple screen.

    To anybody that may have some advice. I hadn't used my power mac in about 4 days then when I turned it on last night it wouldn't boot past the white apple screen. I still have the chime my fans and processor still spin up. I tried resetting the SMU,

  • What is the max number of SMS & MMS messages that the iphone can store?

    iOS currently has a limit of 100 phone calls that can be stored in the call log. Is there a similar limit for SMS or MMS messages? If so, what it is? Where is this documented?

  • My iPhone 5 sound will not work!

    I will only have sound when on speaker phone or when the headphones are plugged in.  I have tried to restart the phone and plug it into itunes with no luck.  Will still vibrate and says that the ringer is in (headphones) but they are not plugged into