如何配置tomcat使得读取到项目之外的文件
答案:2 悬赏:0 手机版
解决时间 2021-11-09 03:19
- 提问者网友:练爱
- 2021-11-08 22:00
如何配置tomcat使得读取到项目之外的文件
最佳答案
- 五星知识达人网友:行雁书
- 2021-11-08 22:48
去看看Java如何用IO读取文件的,就行了。给你个文件复制的例子,把D盘1.txt文件拷贝到D盘2.txt文件中,参考下,改改就能用了。
public class TesiIO_1 {
public static void main(String[] args) {
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(new File("D:/1.txt"));
os = new FileOutputStream(new File("d:/2.txt"));
int length = 0;
byte[] bs = new byte[1024];
while ((length = is.read(bs, 0, bs.length)) != -1) {
os.write(bs, 0, length);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
is.close();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public class TesiIO_1 {
public static void main(String[] args) {
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(new File("D:/1.txt"));
os = new FileOutputStream(new File("d:/2.txt"));
int length = 0;
byte[] bs = new byte[1024];
while ((length = is.read(bs, 0, bs.length)) != -1) {
os.write(bs, 0, length);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
is.close();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
全部回答
- 1楼网友:蕴藏春秋
- 2021-11-08 23:38
我暂时保留我的看法!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯