当前位置:网站首页>Advanced API
Advanced API
2022-07-01 08:31:00 【Chasing dream Zichen】
One . Operation package of file io
1.File class :input( Input ) output( Output )
(1)isFile: Determine if it's a document
(2)isDirectory: Determine if it's a directory ( Folder )
(3)isHidden Determine whether it is a hidden file
(4)exists Determine whether the associated file exists
(5)createNewFile Create a file
(6)mkdir Create a folder
(7)getPath Get the path to the file
getName Get the filename
getParent Get the name of the last parent directory of the file ( Parent path )
(8)length Get file length , In bytes
(9)lastModified Get the last modification time of the file The return type is long
(10)delete Delete the file with the specified path
(11)list Get the names of all the files under the folder
listFile Get all the file objects under the folder
(12)listRoots Get the drive letter of the current system
2. read (Input)
(1)FileInputStream: File reading .read
(2)byte[] bs = new byte[(int)file.length()]; Make the length of byte array consistent with the file length
(3)String str = new String(bs) Convert byte array to string
(4).close; Closed flow
3. Write (Output)
(1)FileOutputStream: File write .write
(2)byte[] bs = str.getBytes(); take String Convert to byte array
(3) Solve the coverage problem ( Read out the contents first And then write it together with the user input )
Be careful : The buffer stream must be closed first , Turn off other flows
4. Buffer flow (BufferedInputStream && BufferedOutputStream)
(1)BufferedInputStream The basic usage and FileInputStream It's almost the same
But buffering the stream reduces the number of disks IO The cost of , Its performance is higher than FileInputStream and FileOutputStream
(2) serialize : Convert an object from memory to media ( Media on the hard disk ) The process of
Each object to be serialized must implement one Serializable Interface
(3) Deserialization : Restore objects from hard disk to memory Read the contents of the object
Two . Character stream
1.
Reader class :FileReader and BufferedReader
Writer class :FileWriter and BufferdeWriter
2. The Internet (.net)
(1) Get your own computer :InetAddress.getLocalHost()
(2) Get other people's computers in the LAN :InetAddress.getByName(“ip Address ”);
(3) Get computers on the Internet :URL url = new URL( For example, Baidu ) InputStream is = url.openStream();
The character stream must be added utf-8, Avoid random code
3. Convert byte stream to character stream —— Using bridges :InputStreamReader
Be careful : In the process of converting a byte stream to a character stream , The code may be garbled , You need to set the encoding method , The only encoding method that supports Chinese is 3 Kind of , Namely :gbk utf-8 gb2312
Pattern: The compiled representation of regular expressions
Matcher: The engine that performs the matching operation
// Bridge conversion
inputStreamReader: The read stream of bytes –> Read stream of characters
outputStreamWriter: Write bytes to the stream –> Character write stream
The general idea of chatting between client and server :
- 1. Start the server
- 1.1 Wait for the client to go online
- 2. The client connects to the server
- 3. The client sends information to the server
- 4. The server receives information from the client
- 5. The server replies to the client information
- 6. The client receives server information
- 7. Close all connections
The general idea of downloading files :
- 1. Start the server and wait for the client to go online
- 2. The client connects to the server
- 3. The client tells the server the file name to download
- 4. The server receives the file name and finds the corresponding file locally *
- 5. The server reads the file from the hard disk to the memory , And then write it to the network *
- 6. The client downloads the file from the network , And save to local *
- 7. Close the connection
5. The use of multithreading ( Flying Pig 、 Slot machine games )
currentThread: Current thread
setPriority(Thread.MAX_PRIORITY); Top priority
setPriority(Thread.MIN_PRIORITY); Lowest priority
.yield();// Discard current CPU resources Start the next grab again
.join();// This thread takes precedence Keep other threads waiting , Will take up resources
.interrupt();// interrupt sleep Threads
.suspend();// Suspend the thread
.resume();// Resume thread execution
synchronized: Sync {
// These must be put in the synchronization method , Otherwise, an error will be reported
.wait();// wait for : Let resources out
.notify();// Wake up the
.notifyAll();// Wake up all
}
// Interview questions :100 Addition and subtraction within Factory production and sales
Be careful : Production methods and sales methods must be synchronized
// Multi person chat room :
1、 Start the service ( A multithread is specially developed to connect )
1.1. Get information about the current client
1.2. Send this message to all my clients ( The server reads messages , And then write , Send to all other clients )
2、 Between customers read Write
TCP:ServerSocket and Socket
6、UDP: There are three kinds of :DatagramSocket and DatagramPacket
1、 unicast : It refers to sending packets to only one fixed machine
2、 radio broadcast : Is to 255.255.255.255 send out , All machines listening to a port can receive
3、 Multicast : Is to send to a user group , All users in this group can receive (224-239)
边栏推荐
- SPL installation and basic use (II)
- Transaction method call @transactional
- SPL Introduction (I)
- DID的使用指南,原理
- Leetcode t40: combined sum II
- Koltin35, headline Android interview algorithm
- OJ输入输出练习
- How can beginners correctly understand Google's official suggested architectural principles (questions?)
- Maneuvering target tracking -- current statistical model (CS model) extended Kalman filter / unscented Kalman filter matlab implementation
- getInputStream() has already been called for this request
猜你喜欢

On several key issues of digital transformation

DID的使用指南,原理

P4 安装bmv2 详细教程

CPU设计实战-第四章实践任务一简单CPU参考设计调试

使用beef劫持用戶瀏覽器
![[getting started] enter the integer array and sorting ID, and sort its elements in ascending or descending order](/img/87/07783593dbabcf29700fa207ecda08.png)
[getting started] enter the integer array and sorting ID, and sort its elements in ascending or descending order

機動目標跟踪——當前統計模型(CS模型)擴展卡爾曼濾波/無迹卡爾曼濾波 matlab實現

shardingSphere

Erreur de hauteur du clavier souple

基于Gazebo的无人机管道检测
随机推荐
Serial port oscilloscope software ns-scope
Leetcode t39: combined sum
XX攻击——反射型 XSS 攻击劫持用户浏览器
[getting started] intercepting strings
Anddroid text to speech TTS implementation
empirical study and case study
Agrometeorological environment monitoring system
CPU设计实战-第四章实践任务一简单CPU参考设计调试
Yolov5进阶之六目标追踪环境搭建
[dynamic planning] p1020 missile interception (variant of the longest increasing subsequence)
機動目標跟踪——當前統計模型(CS模型)擴展卡爾曼濾波/無迹卡爾曼濾波 matlab實現
On June 30, 2022, the record of provincial competition + national competition of Bluebridge
Soft keyboard height error
初学者如何正确理解google官方建议架构原则(疑问?)
P4 安装bmv2 详细教程
Intelligent water conservancy solution
Keithley 2100 software 𞓜 Keithley2400 test software ns SourceMeter
Leetcode T29: 两数相除
Chinese font Gan: zi2zi
【Redis】一气呵成,带你了解Redis安装与连接