当前位置:网站首页>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)
边栏推荐
- 网关gateway-88
- 【无标题】
- How to prevent the other party from saying that he has no money after winning the lawsuit?
- 使用beef劫持用户浏览器
- To prevent "activation" photos from being muddled through, databao "live detection + face recognition" makes face brushing safer
- Leetcode T34: 在排序数组中查找元素的第一个和最后一个位置
- 軟鍵盤高度報錯
- Pipeline detection of UAV Based on gazebo
- [no title] free test questions for constructor municipal direction general foundation (constructor) and theoretical test for constructor municipal direction general foundation (constructor) in 2022
- How to recruit Taobao anchor suitable for your own store
猜你喜欢
![[untitled]](/img/b9/6922875009c2d29224a26ed2a22b01.jpg)
[untitled]

shardingSphere

factory type_id::create过程解析

Huawei machine test questions column subscription Guide

C basic knowledge review (Part 4 of 4)

【Redis】一气呵成,带你了解Redis安装与连接

Manually dig XSS vulnerabilities
![[staff] key number (key number identification position | key number marking list | a major key identification principle | F, C, G position marking ascending | F major key identification principle | B](/img/48/e98d01830867baa742574e1b6e1096.jpg)
[staff] key number (key number identification position | key number marking list | a major key identification principle | F, C, G position marking ascending | F major key identification principle | B

【无标题】

【刷题】字符统计【0】
随机推荐
How can beginners correctly understand Google's official suggested architectural principles (questions?)
一套十万级TPS的IM综合消息系统的架构实践与思考
Yolov5进阶之七目标追踪最新环境搭建
Provincial election + noi Part VI skills and ideas
[deep analysis of C language] - data storage in memory
factory type_id::create过程解析
Airsim雷达相机融合生成彩色点云
Keithley 2100 software 𞓜 Keithley2400 test software ns SourceMeter
Uni hot update
P4 installation bmv2 detailed tutorial
Leetcode T39: 组合总和
【Redis】一气呵成,带你了解Redis安装与连接
[staff] key number (key number identification position | key number marking list | a major key identification principle | F, C, G position marking ascending | F major key identification principle | B
Intelligent water supply system solution
leetcode T31:下一排列
Chinese font Gan: zi2zi
DID的使用指南,原理
MATLAB小技巧(23)矩阵分析--模拟退火
初学者如何正确理解google官方建议架构原则(疑问?)
Koltin35, headline Android interview algorithm