当前位置:网站首页>Review the first three IO streams
Review the first three IO streams
2022-06-13 03:36:00 【Mouth strong programmer】
package com.zking.test;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.net.URL;
public class MyDemo01 {
public static void main(String[] args) throws Exception {
//S2- senior API
//1.IO flow 2.NET Network programming 3. Multithreading
//2.IO The core of the stream : Read and write files
//2.1 File class —— Describe the folders and file objects on the disk
// How to describe a file or folder adopt File Class constructor
//File file = new File("D:\\a.txt");
File file = new File("D:\\a.txt");
// New features
file.createNewFile();
file.mkdir();
file.mkdirs();
// Judgment function
file.exists();
file.isFile();
file.isDirectory();
file.isHidden();
// Delete function
file.delete();
// obtain
file.getPath();
file.getAbsolutePath();
file.getName();
file.getParent();
file.lastModified();
file.length();
file.list();
file.listFiles();
// recursive : The method itself calls itself ----- Method
// File file2 = new File("C:\\");
// findFileAll(file2);
//IO flow : Read and write
//I---Input Input -------》 Read
//O---Output Output ---------》 write in
// In the direction of the flow ------- Input stream ( Read ) Output stream ( write in )
// According to the type of flow ------- Byte stream ( byte ) Character stream ( character )
// According to the way the stream is handled ----- Node flow Processing flow (Buffered)
// Byte stream And byte processing stream
// Handling of all documents
//FileInputStream
//FileOutputStream
/*
technological process :
1. adopt File Object to build a file path object
2. Building a byte input stream or output stream object will File Objects are packaged
3. Call the read or write method to process
4. All critical resources
*/
// write in a To D:\\a.txt
File newFile = new File("D:\\a.txt");
FileOutputStream fos = new FileOutputStream(newFile);
fos.write('a');
fos.close();
System.out.println(" Operation is completed ");
// Processing flow --- Buffer stream of bytes
//BufferedInputStream
//BufferedOutputStream
BufferedOutputStream bos = new BufferedOutputStream(fos);
//day03 Serialization and deserialization ————————IO flow Stream object
// serialize : Save objects to a file by streaming ObjectOutputStream
// Deserialization : Read the objects in the file to the memory by streaming ObjectInputStream
Student stu = new Student(" Zhang San ");// object
File file3 = new File("D:\\sb.bak");
FileOutputStream fos2 = new FileOutputStream(file3);
ObjectOutputStream oos = new ObjectOutputStream(fos2);
oos.writeObject(stu);
oos.close();
fos2.close();
//day04- Character stream
//Writer write in Output
//Reader Read Input
// Stream to file
// FileWriter
// FileReader
// BufferedWriter
// BufferedReader
// Intermediate conversion flow ----- Consider a coding problem
// InputStreamReader
// OutputStreamWriter
// InputStreamReader isr = new InputStreamReader(in, cs);
// Chinese code : GBK GB2312 UTF-8
// pure English ISO-8859-1
// Network programming URL
//URL---- Uniform resource placeholder
//http://193.168.3.82:8080/web_01/index.html?username=admin
// Address | website
// agreement
// domain name
// Port number
// Resource name
// Specific page
// Parameters
URL url = new URL("https://www.shijuepi.com/uploads/allimg/200918/1-20091Q10417.jpg");
InputStream is = url.openStream();
BufferedInputStream bis = new BufferedInputStream(is);
// Output stream ---- Role of preservation
File fileImg = new File("D:\\a.jpg");
FileOutputStream fosImg= new FileOutputStream(fileImg);
BufferedOutputStream bosImg = new BufferedOutputStream(fosImg);
int len = 0;
while(-1!=(len = bis.read())) {
bosImg.write(len);
bosImg.flush();
}
// close resource
//
System.out.println("OK");
}
// lookup D All files on disk
public static void findFileAll(File file) {
if(file.isFile()) {// It's a document
System.out.println(file.getName());
}else if(file.isDirectory()){
File[] listFiles = file.listFiles();
// Filter the hidden files of the system
if(null == listFiles) {
return;
}
// Traverse
for (File file2 : listFiles) {
findFileAll(file2);
}
}
}
}
io Stream save object serialization Use objects with deserialization
package com.zking.test;
import java.io.Serializable;
public class Student implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
String name;
public Student(String name) {
super();
this.name = name;
}
}
边栏推荐
- Spark core concepts: Master, worker, driver program, executor, RDDS
- Three ways of scala string interpolation
- MySQL learning summary 12: system variables, user variables, definition conditions and handlers
- MapReduce internal execution principle
- Transaction processing in PDO
- P1048 [noip2005 popularization group] Drug collection
- Use of compact, extract and list functions in PHP
- Configuration and practice of shardingsphere JDBC sub database separation of read and write
- Druid query
- [synchronization function] version 2.0.16-19 has the update of synchronization function repair, but the problem has not been solved
猜你喜欢
[azure data platform] ETL tool (1) -- Introduction to azure data factory
Aggregation analysis of research word association based on graph data
ONNX+TensorRT+YoloV5:基于trt+onnx得yolov5部署1
Doris data backup and recovery
Onnx+tensorrt+yolov5: yolov5 deployment based on trt+onnx 1
Neo4j auradb free, the world's leading map database
【youcans 的 OpenCV 例程200篇】201. 图像的颜色空间转换
2000-2019 enterprise registration data of all provinces, cities and counties in China (including longitude and latitude, registration number and other multi indicator information)
Patrick Pichette, partner of inovia, former chief financial officer of Google and current chairman of twitter, joined the board of directors of neo4j
Window and various windowfunctions in Flink
随机推荐
Filters in PHP
[azure data platform] ETL tool (7) - detailed explanation of ADF copy data
Spark optimization - Performance (general performance, operator, shuffle, JVM) tuning
Golang picks up: why do we need generics
Azure SQL db/dw series (11) -- re understanding the query store (4) -- Query store maintenance
Four ways of array traversal in PHP
Get to know druid IO real time OLAP data analysis storage system
C language programming -- input a string (including letters, numbers, punctuation marks, and space characters) from the keyboard, calculate the actual number of characters and print out, that is, it d
Application scenarios of large arrows in Scala
300W pieces of MySQL data were written in the test, and they were broken between 1.6 and 2W each time. Then the following problems occurred:
Azure SQL db/dw series (9) -- re understanding the query store (2) -- working principle
Serialization & deserialization
[azure data platform] ETL tool (4) - azure data factory debug pipeline
Union, intersection and difference sets of different MySQL databases
Masa Auth - SSO and Identity Design
Summary of virtualization technology development
Several functions in YAF framework controller
MySQL learning summary 10: detailed explanation of view use
Economic panel topic 1: panel data of all districts and counties in China - more than 70 indicators such as population, pollution and agriculture (2000-2019)
Simulink code generation: simple state machine and its code