Java.io,printwriter can be used to create a file and write data to this document

Source: Internet
Author: User



Java.io,printwriter can be used to create a file and write data to this document

PrintWriter(String filename);PrintWriter(File file);<!--创建一个向指定文件的新的PrintWriter-->PrintWriter(OutoutStream out);PrintWriter(OutoutStream out,Boolean antoflush);<!--创建一个中介输出流,创建一个向此输出流写入数据的新的PrintWriter-->PrintWriter(Writer out);PrintWriter(Writer out,Boolean );<!--创建一个新的PrinWriter-->print(Object obj);<!--通过打印从toString产生的字符串来打印一个对象-->print(String s);<!--打印一个字符串-->print(char[] c);<!--char[] s--><!--打印一个字符数组-->print(int i);print(long i);print(float f);print(double d);print(boolean b);打印对应的类型


For example:

Import Java.io.file;import Java.io.filenotfoundexception;import java.io.PrintWriter; Public classWriteData { Public Static void Main(string[] args) throws filenotfoundexception{File file=NewFile ("Num.txt");//File Object         if(File.exists ()) {System. out. Print ("The file already exists!" "); System.exit (0); } printwriter out=NewPrintWriter (file);//Construct a writer from a file object          out. println ("John,where is you?"); out. println ("I am here!"); out. println ("How old is you ?"); out. println ( the);//Turn off the writer          out. Close (); }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java.io,printwriter can be used to create a file and write data to this document

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.