The file IO in Java7 has changed a lot and has introduced many new classes specifically:Import Java.nio.file.DirectoryStream;Import Java.nio.file.FileSystem;Import Java.nio.file.FileSystems;Import Java.nio.file.Files;Import Java.nio.file.Path;Import java.nio.file.Paths;Import Java.nio.file.attribute.FileAttribute;Import java.nio.file.attribute.PosixFilePermission;Import java.nio.file.attribute.PosixFilePerm
longer readwhile ((N=fis.read (words))!=-1) {//6. Read the information in the file input stream until-1 endsFos.write (Words,0,n); 7. The file output stream is written to read the content length in the words array is 0-n}System.out.print ("File copy succeeded, view file");}catch (Filenotfoundexcepton e) {//The first i
1. Object serialization is to save the current state of the object.
2.There are two main ways to save the object status:
1)Object serialization (write the object to a file and deserialize it later, as shown in the following example)
If the stored data is used in JavaProgramObject serialization is used for internal interaction;
2)Write a file (write an object to a text
in accordance with the written order, or read out is garbledSystem.out.println (Dis.readbyte ()); System.out.println (Dis.readlong ()); System.out.println (Dis.readchar ()); System.out.println (Dis.readutf ()); //5. Close the streamDis.close (); Bis.close (); Fis.close (); System.out.println ("Read the file complete!" "); } Catch(FileNotFoundException e) {e.printstacktrace (); } Catch(IOException
-Writer.append ("中文版")); + //Close closes the write stream, which writes the contents of the buffer to the file - writer.close (); + //turn off the output stream A fop.close (); at - /** - * read out the file - */ - //Building FileInputStream Objects -FileInputStream FIP =NewFileInputStream (f); in //build the InputStreamReader object with the same encoding
The instance describes Java IO file replication, and the instance describes javaio
IO streams are mainly divided into two categories: byte streams and byte streams.
Note:
1. audio files, images, and videos (with a wide range) are throttled by words
2. if it involves only the text, the ghost stream is used.
Use byte str
The file IO in Java7 has changed a lot and has introduced many new classes specifically:Import Java.nio.file.DirectoryStream;Import Java.nio.file.FileSystem;Import Java.nio.file.FileSystems;Import Java.nio.file.Files;Import Java.nio.file.Path;Import java.nio.file.Paths;Import Java.nio.file.attribute.FileAttribute;Import java.nio.file.attribute.PosixFilePermission;Import java.nio.file.attribute.PosixFilePerm
(); - } - } - } -}Run the program and console outputs the characters entered in the Test.txt.Case 2:Demonstrate the use of FileOutputStream (save the input string to a file)1 Public classDemo_3 {2 3 Public Static voidMain (string[] args) {4 5File f=NewFile ("E:\\ss.txt");6FileOutputStream fos=NULL;//byte output stream7 8 Try {9fos=NewFileOutputStream (f);Ten OneString s= "Hello, lunatic!" \ r
The byte array input stream creates a byte array buffer in memory, and the data read from the input stream is saved in the byte array buffer. There are several ways to create a byte array input stream Object.The receive byte array is created as a parameter:New Bytearrayinputstream (byte [] a);Another way to create this is to receive a byte array, and two shaping variables off, Len,off represents the first read byte, and Len represents the length of the read Byte.New Bytearrayinputstream (byteint
FileFile can create new, delete, rename files and directories, but cannot view file contents.Construction methodpublic File(string pathName);//以path路径创建对象publicFile(StringString child);//以parent为父路径,child为子路径创建File对象Unix under Path delimiter is '/', Windows is ' \ ' or '/'A program that understands the file class//crea
JAVA 47th-IO stream (1): file read/write
Input stream and output stream relative to memory
Read data from external devices to memory: Input
Write data in memory to external devices: Output
I/O streams often use base classes
Abstract base class of byte stream: InputStream, OutputStream
Abstract base class of characters: Reader and Writer
PS: The child classes gene
2017-10-30The interview in the previous days when the exam two questions, are related to the Java Foundation:
Use Java IO package to read and write files;
Use JDBC to get the data.
It is a pity that I could not remember the basic knowledge, so it is necessary to tidy up and consolidate this knowledge.In this summary, I will summarize the read-wr
----------------------
Android training and Java training. We look forward to communicating with you! ----------------------
Through this program, you can understand the operations of various files in the Java. Io. File class: Import java.
I am not very familiar with IO operations... Encoding and garbled characters are also unknown... Today I met a requirement to encode a file and return the encoded string, such as the original GBK encoding, to the UTF-8
Here, the BytesEncodingDetect class will not be pasted. It mainly uses the get file encoding format.
At the beginning, I tried to change the enc
Java IO stream technology-File, javaio
IO stream technology
Concept: input-output:
Input: Read the file to the memory;
Output: write files from memory to other places
Role: mainly solves the problem of data transmission between devices.
Original: Java vs. io and NiO file read/write performance testSource code: Http://www.zuidaima.com/share/1550463508466688.htm1. NIO uses a way closer to the operating system to execute IO: Channels and buffers, as the name implies, data source data is transmitted by the buffer through the channel. 2. After JDK5, the ra
Today saw a netizen write Java file monitoring, real-time monitoring file loading, suddenly think of commons-io in the implementation of this function, first review to write a simple demo:There are three ways of doing this:1, Java Common.io Internal implementation is the way
JAVA 52nd-IO stream (6) File object
File class
Used to encapsulate files or folders as objects.
Convenient operations on file and folder attributes
The File object can be passed to the stream constructor as a parameter.
1. constru
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.