当前位置:网站首页>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)
边栏推荐
- [getting started] input n integers and output the smallest K of them
- Cmake I two ways to compile source files
- 2022.6.30 省赛+蓝桥国赛记录
- SPL-介绍(一)
- Keithley 2100 software 𞓜 Keithley2400 test software ns SourceMeter
- 使用beef劫持用户浏览器
- Pipeline detection of UAV Based on gazebo
- EDA open source simulation tool verilator beginner 6: debugging examples
- 01 numpy introduction
- [deep analysis of C language] - data storage in memory
猜你喜欢

SPL-介绍(一)

Intelligent water and fertilizer integrated control system

Erreur de hauteur du clavier souple

《MATLAB 神经网络43个案例分析》:第30章 基于随机森林思想的组合分类器设计——乳腺癌诊断

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

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

Pipeline detection of UAV Based on gazebo

【js逆向】md5加密参数破解

Utiliser Beef pour détourner le navigateur utilisateur

华为机试真题专栏订阅指引
随机推荐
CPU設計實戰-第四章實踐任務一簡單CPU參考設計調試
初学者如何正确理解google官方建议架构原则(疑问?)
【js逆向】md5加密参数破解
机动目标跟踪——当前统计模型(CS模型)扩展卡尔曼滤波/无迹卡尔曼滤波 matlab实现
getInputStream() has already been called for this request
数字转excel的字符串坐标
Yolov5进阶之六目标追踪环境搭建
[untitled]
DID的使用指南,原理
MATLAB小技巧(23)矩阵分析--模拟退火
Leetcode T29: 两数相除
Access report realizes subtotal function
2022.2.15
Serial port oscilloscope software ns-scope
[深度剖析C语言] —— 数据在内存中的存储
Conception et mise en service du processeur - chapitre 4 tâches pratiques
毕业论文中word的使用1-代码域标公式
使用threejs简单Web3D效果
To prevent "activation" photos from being muddled through, databao "live detection + face recognition" makes face brushing safer
Leetcode T34: 在排序数组中查找元素的第一个和最后一个位置