当前位置:网站首页>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 .
边栏推荐
- Leetcode1984. Minimum difference in student scores
- 面试百问:如何测试App性能?
- One question per day - pat grade B 1002 questions
- I wish you all the best and the year of the tiger
- [language programming] exe virus code example
- oc 可变參数传递
- Digital transformation: five steps to promote enterprise progress
- 筑起云端 “免疫”屏障,让你的数据有备无患
- ADC采样率(HZ)是什么怎么计算
- 消费品企业敏捷创新转型案例
猜你喜欢
微服務遠程Debug,Nocalhost + Rainbond微服務開發第二彈
Microbial health network, how to restore microbial communities
行测-图形推理-8-图群类
线上面试,该如何更好的表现自己?这样做,提高50%通过率~
Microservice Remote debug, nocalhost + rainbond microservice Development second Bomb
Line test graph reasoning graph group class
Early childhood education industry of "screwing bar": trillion market, difficult to be a giant
Cases of agile innovation and transformation of consumer goods enterprises
Unity与WebGL的相爱相杀
行测-图形推理-4-字母类
随机推荐
行测-图形推理-8-图群类
微生物健康网,如何恢复微生物群落
Debezium series: binlogreader for source code reading
数字藏品加速出圈,MarsNFT助力多元化文旅经济!
Basic knowledge of binary tree
LeetCode142. Circular linked list II [two pointers, two methods for judging links in the linked list and finding ring points]
Line test - graphic reasoning -5- one stroke class
Software evaluation center ▏ what are the basic processes and precautions for automated testing?
Select sort (illustration +c code)
What is ADC sampling rate (Hz) and how to calculate it
Leetcode94. Middle order traversal of binary trees
[untitled] reprint melting ice - track icedid server with a few simple steps
“拧巴”的早教行业:万亿市场,难出巨头
Visual studio 2019 installation
知识点滴 - PCB制造工艺流程
Line test - graphic reasoning - 3 - symmetric graphic class
Interview questions: how to test app performance?
Debezium series: MySQL tombstone event
Time convolution Network + soft threshold + attention mechanism to realize residual life prediction of mechanical equipment
小程序多种开发方式对比-跨端?低代码?原生?还是云开发?