如何使用文件中的write()编写数组

时间:2016-08-24 17:55:03

标签: java file

此处无法使用fos.write(Arrays.toString(mark[]));。我该怎么做才能写出数组值?

class Write {
public static void main(String[] args) {
    try {
        FileOutputStream fos = new FileOutputStream("D:\\file program\\hai.txt");
        String name = Streams.readName();
        fos.write(name.getBytes());
        fos.flush();
        //fos.close();
        int[] mark = Streams.readMark();
        fos.write(Arrays.toString(mark[]));
        fos.flush();
        fos.close();
        System.out.println("data entred");
    } catch (FileNotFoundException ex) {
    }
        catch (IOException e) {
    }
}}

我的输出:

My output

1 个答案:

答案 0 :(得分:2)

fos.write(Arrays.toString(mark[]));不正确

删除 []

然后尝试:

 fos.write(Arrays.toString(mark));