当前位置:网站首页>Basic use of BufferedReader and bufferedwriter
Basic use of BufferedReader and bufferedwriter
2022-06-11 06:01:00 【Not bald】
Bufferedreader And Bufferedwriter Basic use of
import java.io.*;
public class IOTest {
public static void main(String[] args) {
// Efficient buffered input stream
BufferedReader reader = null;
try {
// What's coming in is reader Subclasses of
reader = new BufferedReader(new FileReader("test.txt"));
String line;
// If there is another line, just keep reading readLine() Used to read a line
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
// Efficient buffered output stream
BufferedWriter writer = null;
BufferedReader reader1;
try {
// Create an efficient buffered output stream
writer = new BufferedWriter(new FileWriter("test1.txt"));
// Create an efficient buffered input stream
reader1 = new BufferedReader(new FileReader("test.txt"));
String line;
while ((line = reader1.readLine()) != null) {
writer.write(line);
writer.newLine();
writer.flush();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (writer != null) {
writer.close();
}
if (reader != null) {
writer.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
BufferedReader It's a buffered character input stream . It is inherited from Reader.BufferReader Will be the Reader The data in is read in batches , Read a portion at a time into the buffer ; After this part of the buffer has been manipulated , Again from Reader To read the data for the next section .
BufferedWriter It's a buffered character output stream . It is inherited from Writer.BufferedWriter To add some buffering to other character output streams .BufferedWriter Buffer data through character arrays , When the buffer is full or the user calls flush() Function time , It writes the buffer data to the output stream .
Bufferedreader
Usually use while((***.readLine)!= null){} To read as characters . as follows :
while ((result = br.readLine()) != null) {
System.out.println(" Read file =" + result);
bw.write(result);
}
At the same time, it also has the function of comparing the contents in the file with the obtained contents
for example
if (byt.compareTo(name+" "+password) == 0)
Bufferedwriter
BufferedWriter bw = new BufferedWriter(newFileWriter("student.txt"));
bw.write("this is my student.txt");
bw.newLine();
bw.write("xixi");
bw.close();
Bufferedwriter The common methods of are the above methods ,write write in ,newLine Line break .
边栏推荐
- What is a planning BOM?
- What should the cross-border e-commerce evaluation team do?
- Error:Execution failed for task ':app:buildNative'. & gt; A problem occurred'x/x/x/'NDK build' error resolution
- NDK learning notes (12) native graphics API, using avilib to create an avi video player
- Aurora im live chat
- OJDBC在Linux系统下Connection速度慢解决方案
- How to deal with message blackout and message sending failure of Aurora im
- Altiumdesigner2020 import 3D body SolidWorks 3D model
- Gilde failed to go to the listener to call back the reason record when loading the Gaussian blur image
- Clear function of ArrayList
猜你喜欢

Thymeleafengine template engine

数据接入平台方案实现(游族网络)

JIRA software annual summary: release of 12 important functions

How to use perforce helix core with CI build server

亚马逊、速卖通、Lazada、虾皮平台在用911+VM的环境可以进行产号、养号、补单等操作吗?

More than 20 cloud collaboration functions, 3 minutes to talk through the enterprise's data security experience

Twitter data collection (content, fans, keywords, etc.)

NFC Development -- difference between ID card and IC card (M1 card and CPU card) (III)

Getbackgroundaudiomanager controls music playback (dynamic binding of class name)
![Yoyov5's tricks | [trick8] image sampling strategy -- Sampling by the weight of each category of the dataset](/img/54/f6a3e0ef1f77901506642784e6d3b7.png)
Yoyov5's tricks | [trick8] image sampling strategy -- Sampling by the weight of each category of the dataset
随机推荐
NDK learning notes (II)
Wechat custom component - style - slot
Continuous update of ansible learning
NDK learning notes (x) POSIX socket for connectionless communication
Observer mode (listener mode) + thread pool to realize asynchronous message sending
Install Oracle Database
NDK learning notes (VI) Basics: memory management, standard file i/o
NFC Development -- utility tools and development documents (IV)
数据接入平台方案实现(游族网络)
Further efficient identification of memory leakage based on memory optimization tool leakcanary and bytecode instrumentation technology
All questions and answers of database SQL practice niuke.com
Distributed framework ray - detailed introduction to starting ray and connecting clusters
Functional interface lambda, elegant code development
The artistic director and production designer of Disney's Mandalorian revealed the virtual scene production behind it
Implementation of data access platform scheme (Youzu network)
YOLOv5的Tricks | 【Trick8】图片采样策略——按数据集各类别权重采样
Installing and using sublist3r in Kali
[must see for game development] 3-step configuration p4ignore + wonderful Q & A analysis (reprinted from user articles)
NDK learning notes (14) create an avi video player using avilib+window
Informatica: six steps of data quality management