IO stream 05 -- video Study Notes for bixiangdong JAVA basic tutorial, 05 -- bixiangdong
Day20
10 create a java file list11 Properties12 Properties access13 Properties14 Properties exercises15 PrintWriter16 merge streams17. Cut files
10 create a java file list
Exercise:Store the absolute path of a
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 file. Note thatText Files)
If the stored data is used to interact with other non-
According to UNIX network programming, IO models can be divided into: blocking io, non-blocking io, io multiplexing, signal-driven IO, and asynchronous Io, divided into two classes according to POSIX standards: synchronous
The so-called IO, which is the abbreviation of input and output. In Java, IO involves a relatively large scope, which focuses on reading and writing about file content
Other knowledge points will be placed in subsequent chapters (I think, the article is too long, no one has the patience to turn to the end)
the operation of the contents of the file is mainly div
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
will be accepted.
Source: System. in)Purpose: To log on to the console (System. out)1/* write the conversion stream and convert the bytes stream to the byte stream */2 import java. io. *; 3 public class TransStreamDemo2 4 {5 public static void main (String [] args) throws IOException 6 {7 // InputStream in = System. in; 8 // InputStreamReader isr = new InputStre
parameter: The associated object that is bound to the IO operation public class Servercompletionhandler implements Completionhandlerpublic class Client {private asynchronoussocketchannel ASC; Public Client () throws Exception {ASC = Asynchronoussocketchannel.open (); } public void Connect () throws Interruptedexception, executionexception{//Get () block Asc.connect (new I Netsocketaddress ("127.0.0.1", 8765)). get (); } public void write (Strin
first look at a few common Encoding Methodpublic class Encodedemo{public static void Main (string[] agrs) throws ioexception{string s= "China abc"; byte[] byte1= S.getbytes (); The default is the project's UTF-8 encoding byte[] byte2=s.getbytes ("GBK");//display the specified encoding mode is gbkbyte[] byte3=s.getbytes ("utf-16be"); for (byte b:byte1) {/** * converts bytes to int in 16 binary display * The default is the project's code, where UTF-8 i
thread can only do one thing, then we can let the server information read and write in a sub-thread, each user by a child thread user information read and send, this thread should have all the information of that user, also called this thread is the interface thread, All interface threads can be accessed indirectly through an interface thread in the server. Key code :Arraylistwhile (true) { try { Socket socket=serversocket.accept (); System.out.println ("There is a client Access server");User
=NewFileOutputStream (NewFile ("Test.txt")); } Catch(FileNotFoundException e) {//TODO auto-generated Catch blockE.printstacktrace (); } bufferedoutputstream Bos=NewBufferedoutputstream (FOS); String C= "Java is an object-oriented programming language that can compose cross-platform applications, and is the Java programming language and Java platform (ie, javase)
There are too many APIs related to I/O operations in Java, and for historical reasons, some APIs have been deprecated, sometimes confusing for some beginners, today, I took the time to sort out frequently used stream operations and share them out. If there are any mistakes, please correct them because most of the methods have been commented out, so the test code in main will not write comments.
For theoretical information, refer to NLP.
2008.07.03 was
class provides the ability to read data in advance, which is the function of buffering. You can take a look at its Read method: public synchronized int read () throws IOException { if (pos >= count) { fill (); if (POS >= count) return-1; } return Getbufifopen () [pos++] 0xFF; }As you can see, when Pos>=count, it is time to buffer some data beforehand, then call Fill () to fill the buffe
When the socket receives data, it often throws Java. io. the eofexception is abnormal and there are no clear causes or prompts. Many people are asking this question on the Internet, but no practical solution is found. After research, the problem is solved. The exception stack information is as follows: Java. Io. eofexc
Import Java. Io. file;2 Import Java. Io. ioexception; 3 4 Public Class Test1 { 5 Public Static Void Main (string [] ARGs ){ 6 File F = New File ("D:" + file. Separator + "test.txt "); // To increase portability, we recommend that you use file. separator.
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.