当前位置:网站首页>Handling file exceptions
Handling file exceptions
2022-07-07 23:07:00 【Anny Linlin】
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import javax.imageio.stream.FileImageInputStream;
import org.omg.CORBA_2_3.portable.InputStream;
/*
* Copy java file , exception handling
*/
public class CopyWenjian {
public static void main(String[] args) {
OutputStreamWriter osw = null;
InputStreamReader isr = null;
try{
osw = new OutputStreamWriter(
new FileOutputStream("E:\\EclipseCode\\file\\src\\fos.txt"));
isr = new InputStreamReader(
new FileInputStream("E:\\EclipseCode\\file\\fos.txt"));
int len;
char [] chs = new char[1024];
while((len=isr.read(chs))!=-1){
osw.write(chs);
}
}catch(Exception e){
e.printStackTrace();
}finally {
try{
if(isr!=null){
isr.close();
}
}catch(Exception e){
e.printStackTrace();
}
try{
osw.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
}
The above code is JDK5 How to handle file exceptions before .
public static void main(String[] args) {
try(OutputStreamWriter osw = new OutputStreamWriter(
new FileOutputStream("E:\\EclipseCode\\file\\src\\fos.txt"));
InputStreamReader isr = new InputStreamReader(
new FileInputStream("E:\\EclipseCode\\file\\fos.txt"));)
{
int len;
char [] chs = new char[1024];
while((len=isr.read(chs))!=-1){
osw.write(chs);
}
}catch(Exception e){
e.printStackTrace();
}
}Above is JDK7 Exception handling scheme for .
private static void copyTxt() throws IOException{
OutputStreamWriter osw = new OutputStreamWriter(
new FileOutputStream("fos.txt"));
InputStreamReader isr = new InputStreamReader(
new FileInputStream("fisr.txt"));
try(osw;isr){
int len;
char [] chs = new char[1024];
while((len=isr.read(chs))!=-1){
osw.write(chs);
}
}catch(Exception e){
e.printStackTrace();
}
}Above is JDK7 The following scheme for handling file exceptions .
边栏推荐
- ASP.NET Core入门五
- Unity technical notes (I) inspector extension
- Quick sort (diagram +c code)
- XMIND mind mapping software sharing
- Line measurement - graphic reasoning -9- line problem class
- Database daily question --- day 22: last login
- PCL .vtk文件与.pcd的相互转换
- 三菱PLC slmp(mc)协议
- Qt Graphicsview图形视图使用总结附流程图开发案例雏形
- 30讲 线性代数 第五讲 特征值与特征向量
猜你喜欢

Ligne - raisonnement graphique - 4 - classe de lettres

Early childhood education industry of "screwing bar": trillion market, difficult to be a giant

Micro service remote debug, nocalhost + rainbow micro service development second bullet

行测-图形推理-6-相似图形类

Sword finger offer 55 - I. depth of binary tree

Basic knowledge of linked list

聊聊 Dart 的空安全 (null safety) 特性

Develop those things: go plus c.free to free memory, and what are the reasons for compilation errors?

线上面试,该如何更好的表现自己?这样做,提高50%通过率~

消费品企业敏捷创新转型案例
随机推荐
Txt file virus
7-18 simple simulation of banking business queue
Microservice Remote debug, nocalhost + rainbond microservice Development second Bomb
Apple further entered the financial sector through the 'virtual card' security function in IOS 16
Redis集群安装
ASEMI整流桥KBPC1510的型号数字代表什么
Line test graph reasoning graph group class
Build an "immune" barrier in the cloud to prepare your data
30讲 线性代数 第五讲 特征值与特征向量
Database daily question --- day 22: last login
0-5vac to 4-20mA AC current isolated transmitter / conversion module
Online interview, how to better express yourself? In this way, the passing rate will be increased by 50%~
LeetCode707. Design linked list
Unity technical notes (I) inspector extension
iNFTnews | NFT技术的广泛应用及其存在的问题
Microbial Health Network, How to restore Microbial Communities
Select sort (illustration +c code)
ADC采样率(HZ)是什么怎么计算
Personal statement of testers from Shuangfei large factory: is education important for testers?
LeetCode206. Reverse linked list [double pointer and recursion]