。。。 One of the learning of IO streams ...

Source: Internet
Author: User

Use of File write stream FileWriter:

1 Import Staticorg.junit.assert.*;2 3 ImportJava.io.File;4 ImportJava.io.FileWriter;5 Importjava.io.IOException;6 7 Importorg.junit.Test;8 9 Ten  One  Public classMyTest { A     //writes data to a specified file by a character stream - @Test -      Public voidTestwrite () { theString Path = "F:" +file.separator+ "Demo.txt"; - //If the file does not exist, create the file first -File File =NewFile (path); -         if(!file.exists ()) { +             Try { - file.createnewfile (); +}Catch(IOException e) { A                 //TODO auto-generated Catch block at e.printstacktrace (); -             } -         } -FileWriter FileWriter =NULL; -         Try { -             //in Windows, make sure that files with path paths are present inFileWriter =NewFileWriter (path); -Filewriter.write ("You aren't a good boy!"); to Filewriter.flush (); + filewriter.close (); -}Catch(IOException e) { the             //TODO auto-generated Catch block * e.printstacktrace (); $}finally{Panax Notoginseng             //If you throw an exception, it means that the FileWriter object is not created. -             if(filewriter!=NULL){ the                 Try { + filewriter.close (); A}Catch(IOException e) { the                     //TODO auto-generated Catch block + e.printstacktrace (); -                 } $             } $              -         } -          the          -     }Wuyi  the}

... One of the learning of IO streams ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.