当前位置:网站首页>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)
边栏推荐
- Conception et mise en service du processeur - chapitre 4 tâches pratiques
- 2022 mechanical fitter (primary) examination summary and mechanical fitter (primary) reexamination examination
- [deep analysis of C language] - data storage in memory
- P4 安装bmv2 详细教程
- Data analysis notes 11
- Manually dig XSS vulnerabilities
- 【华为机试真题详解】判断字符串子序列【2022 Q1 Q2 | 200分】
- 使用threejs简单Web3D效果
- String coordinates of number to excel
- SPL-安装与基本使用(二)
猜你喜欢
[getting started] enter the integer array and sorting ID, and sort its elements in ascending or descending order
Adding color blocks to Seaborn clustermap matrix
Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
The use of word in graduation thesis
軟鍵盤高度報錯
P4 安装bmv2 详细教程
[dynamic planning] p1020 missile interception (variant of the longest increasing subsequence)
Burpsuite -- brute force cracking of intruder
[getting started] extract non repeating integers
毕业论文中word的使用1-代码域标公式
随机推荐
基于Gazebo的无人机管道检测
CPU设计实战-第四章实践任务一简单CPU参考设计调试
OJ input and output exercise
[getting started] extract non repeating integers
The use of word in graduation thesis
Programmer's regimen
事务方法调用@Transactional
[Yu Yue education] Shandong Vocational College talking about railway reference materials
Erreur de hauteur du clavier souple
On several key issues of digital transformation
How to use OKR as the leadership framework of marketing department
01 numpy introduction
量化交易之读书篇 - 《征服市场的人》读书笔记
网关gateway-88
7-26 word length (input and output in the loop)
[untitled]
[redis] it takes you through redis installation and connection at one go
Airsim雷达相机融合生成彩色点云
Transaction method call @transactional
初学者如何正确理解google官方建议架构原则(疑问?)