这是我学习文件 i/o 的代码...
import java.io.*;
import java.util.Scanner;
public class UserFILE_IO {
static FileInputStream fin;
static FileOutputStream fout, fout1;
public static void main(String[] args) {
try {
fin = new FileInputStream("ABC.txt");
fout = new FileOutputStream("ABC.txt");
} catch (FileNotFoundException e) {
System.out.println("FILE NOT FOUND!!!");
}
String s;
Scanner sc = new Scanner(System.in);
s = sc.nextLine();
try {
fout.write(s.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
try {
fout.close();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
sc.close();
try {
fout1 = new FileOutputStream("ABC1.txt");
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try {
char c;
while ((c = (char) fin.read()) != -1) {
fout1.write(c);
System.out.print(c);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fin.close();
fout1.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
每当我尝试从工作区文件夹(在 C: 中)打开 ABC1.txt
文件时,它显示的大小为 12.00 MB,并且每当我刷新文件夹时,大小也会每次增加。我想提的另一件事是,我无法在我使用的 IDE (Eclipse) 中看到文件 ABC.txt
。
为什么文件 ABC1.txt 的大小大于 12.00 MB+
为什么我无法在 IDE 中获取 ABC.txt 文件?
最佳答案
您还可以在该包内包含程序源代码的文件夹中找到它。 在这里,由于您没有提到文件的正确路径,因此它必须是默认位置的情况。 尽量把路径写得更精确。
这里的情况可能是这样的,abc.txt同一个文件也可以被文件ABC.txt的内容覆盖,所以,如果存在任何名为abc.txt的文件,那么ypu也应该调查它。
关于java - 文件 I/O 代码记录了几个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32614758/