java对文件进行读写操作的过程是什么
答案:1 悬赏:0 手机版
解决时间 2021-02-26 04:00
- 提问者网友:相思似海深
- 2021-02-25 09:56
可不可以专业一点的
最佳答案
- 五星知识达人网友:鱼忧
- 2021-02-25 10:28
差不多就是下面这样
InputStream is = null;
OutputStream out = null;
try {
File file = new File("c:\\test.txt");
File newFile = new File("d:\\test.txt");
is = new FileInputStream(file);
out = new FileOutputStream(newFile);
byte[] b = new byte[1024];
while(is.read(b) > 0)
{
out.write(b);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally
{
if(is != null)
{
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(out != null)
{
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
InputStream is = null;
OutputStream out = null;
try {
File file = new File("c:\\test.txt");
File newFile = new File("d:\\test.txt");
is = new FileInputStream(file);
out = new FileOutputStream(newFile);
byte[] b = new byte[1024];
while(is.read(b) > 0)
{
out.write(b);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally
{
if(is != null)
{
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(out != null)
{
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯