Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 记录错误:文件I/O_Java_Eclipse_File Io_Logged - Fatal编程技术网

Java 记录错误:文件I/O

Java 记录错误:文件I/O,java,eclipse,file-io,logged,Java,Eclipse,File Io,Logged,在这里,我把我在学习文件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

在这里,我把我在学习文件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();
        }
    }
}
现在我面临的问题是,每当我试图打开

ABC1.txt

工作区文件夹中的文件(C:),它显示12.00 MB的大小,每当我刷新文件夹时,大小也会每次增加。我想说的另一件事是,我看不到文件

ABC.txt

在我正在使用的IDE(Eclipse)中。。。 我想要解决这个问题的办法

1) 为什么文件ABC1.txt的大小大于12.00 MB+

2) 为什么我不能在IDE中获取ABC.txt文件

我明白了!!! 将类范围删除为public,并提及:

class UserFILE_IO{}
您只需将代码更改为:

try{
    fout = new FileOutputStream("ABC.txt");
    fin = new FileInputStream("ABC.txt");
}  
最后将循环更改为:

try {
    char c;
    while ((c = (char) fin.read()) == 1) {
        fout1.write(c);
        System.out.print(c);
    }
那你就一切都好了。

我明白了!!! 将类范围删除为public,并提及:

class UserFILE_IO{}
您只需将代码更改为:

try{
    fout = new FileOutputStream("ABC.txt");
    fin = new FileInputStream("ABC.txt");
}  
最后将循环更改为:

try {
    char c;
    while ((c = (char) fin.read()) == 1) {
        fout1.write(c);
        System.out.print(c);
    }

然后你会把一切都搞定。

你也可以在包含程序源代码的文件夹中找到它。 在这里,由于您没有提到要存储文件的正确路径,因此必须是默认位置。 尝试将路径写得更精确


这里的情况可能类似于,abc.txt相同的文件也可以被abc.txt文件的内容覆盖,因此,如果存在任何名为abc.txt的文件,那么ypu也应该查看它。

您也可以在该包中包含程序源代码的文件夹中找到它。 在这里,由于您没有提到要存储文件的正确路径,因此必须是默认位置。 尝试将路径写得更精确


这里的情况可能类似于,abc.txt相同的文件也可以被abc.txt文件的内容覆盖,因此,如果存在任何名为abc.txt的文件,那么ypu也应该查看它。

是否在输入流中输入abc.txt的路径?我看不到它。它将采用IDE将源代码放在其中的文件夹的默认路径。那么您的ABC.txt是否在该文件夹中?是的,它在我的工作区文件夹中可见。但无法打开。它显示没有响应…您是否正在输入流中输入ABC.txt的路径?我看不到它。它将采用IDE将源代码放在其中的文件夹的默认路径。那么您的ABC.txt是否在该文件夹中?是的,它在我的工作区文件夹中可见。但无法打开。它显示没有响应。。。。