Java 二进制I/O流

Java 二进制I/O流,java,io,javafx,random-access,Java,Io,Javafx,Random Access,我有两个节目。输出一些信息的人: import java.io.*; import java.util.Arrays; import java.util.Date; public class Output { public static void main(String[] args) throws ClassNotFoundException, IOException { int[] numbers = { 1, 2, 3, 4, 5 };

我有两个节目。输出一些信息的人:

import java.io.*;
import java.util.Arrays;
import java.util.Date;

public class Output {
    public static void main(String[] args) throws ClassNotFoundException,
            IOException {

        int[] numbers = { 1, 2, 3, 4, 5 };

        // Create an output stream for binary file
        try (ObjectOutputStream output = new ObjectOutputStream(
                new FileOutputStream("Exercise7_05.dat", true));) 
        {
            // Write to each type to the file
            output.writeDouble(5.5);
            output.writeObject(numbers);
            output.writeObject(new java.util.Date());
            output.writeUTF("Exercise7_05.dat");
        }
    }
}
另一个应该读取二进制输入并将其打印到控制台:

import java.io.*;
import java.util.Arrays;
import java.util.Date;

public class Input {
    public static void main(String[] args) throws ClassNotFoundException,
            IOException {

        /*
         * Create an input stream for binary file to be converted to something
         * readable
         */
        try (ObjectInputStream input = new ObjectInputStream(
                new FileInputStream("Exercise7_05.dat"));) {

            // Read each object from binary file
            double doubleValue = input.readDouble();
            System.out.println("Double value: " + doubleValue);

            int[] newNumbers = (int[]) (input.readObject());
            System.out.println("Integers: " + Arrays.toString(newNumbers));

            Date date = (java.util.Date) (input.readObject());
            System.out.println("DateTime: " + date);

            String fileName = input.readUTF();
            System.out.println("File name: " + fileName);
        }
    }
}
我的问题是,我在尝试运行输入流时出错:

主线程java.io.FileNotFoundException中的异常:Exercise7_05.dat系统找不到指定的文件 在java.io.FileInputStream.openNative方法中 位于java.io.FileInputStream.Unknown Source 位于java.io.FileInputStream.Unknown Source
在application.Input.mainInput.java:18,我猜您是从不同的目录运行它们。我对所有这些都不熟悉,那么您的确切意思是什么呢?您的代码尝试从它运行的任何目录读取文件。如果您运行代码从其他目录写入文件,那么它将无法找到该文件-这将解释您遇到的异常。您没有告诉我们有关如何运行此代码的任何信息,这使您很难获得帮助。对,因此您可以编辑运行配置以确定执行位置。或者从同一目录中的命令行运行。或者在程序中嵌入一个绝对文件名。