Java--Simple use of fileinputstream and FileOutputStream

Source: Internet
Author: User

the basic process for local file read and write programming is:

① generates a file stream object (should be the FileInputStream class for file read operations, and the file should be FileOutputStream Class);

② calls a function function in the FileInputStream or FileOutputStream class, such as read (), write (int b), to read and write the contents of the file;

③ Closes the file (Close ()).


Read the file under a certain path, filename = new file ("D:\\123.txt"), try {fileinputstream fis=new fileinputstream (file);// Create a new FileInputStream object try {byte[] b=new byte[fis.available ()];//Create a new byte array fis.read (b);//reads the contents of the file into a byte array fi      S.close ();      String Str2=new string (b);//The contents of the byte array are then converted into a string output System.out.println (STR2);      } catch (IOException e) {e.printstacktrace (); }} catch (FileNotFoundException e) {e.printstacktrace ();} File writes FileOutputStream file_out = new FileOutputStream (file); File_out.write (outputdata);  Byte data file_out.close ();

Classes inherited from InputStream and outputstream for local file reads and writes (binary format read and write, sequential read and write, separate file stream objects to be created by reading and writing)

Http://www.cnblogs.com/kyxyes/archive/2013/02/16/2913424.html

Http://www.cnblogs.com/jjtech/archive/2011/04/17/2019210.html

Java--Simple use of fileinputstream and FileOutputStream

Related Article

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.