如下代码:
异常原因是因为在输入过着输出流中没有定义文件名,而只有目录。
/**
* 字符流* @author Administrator
*
*/
public class Demo5 {
public static void stream() throws IOException {
InputStream inputStream = new FileInputStream("D:\\测试1\\123.txt");
OutputStream output = new FileOutputStream("D:\\测试2\\"); //here
int b = 0;
while((b = inputStream.read()) != -1) {
output.write(b);
}
inputStream.close();
output.close();
}
public static void main(String[] args) {
try {
stream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
本文通过一个具体的Java代码示例,解析了文件复制过程中出现异常的原因,并提供了相应的解决思路。异常发生在输出流定义不完整时,即仅指定了目标目录而未指定具体文件名。
5818

被折叠的 条评论
为什么被折叠?



