问答详情
源自:5-4 学生选课---修改 Map 中的学生

大神啊,请问。为什么输出的是问号啊?

import java.io.*;

class FileInOutEx{

public static void main(String[] args) throws IOException{

File file_Book1 = new File("Book1.txt");

String bookInfo = "世界是平的\t 350.0\t Friedman\t";

file_Book1.createNewFile(); 

FileOutputStream fos = new FileOutputStream(file_Book1);

fos.write(bookInfo.getBytes());

fos.close();

FileInputStream fis = new FileInputStream(file_Book1);

System.out.println("书籍名称\t 价格\t 作者\t");

System.out.println("---------------------------------------");

int i = 0; 

while((i=fis.read()) != -1)

System.out.print((char)i);

fis.close();

}

}


提问者:qq_童化金_dwxHIS 2019-03-12 15:57

个回答

  • 慕雪0332877
    2019-03-26 14:20:43

    package com.imooc;

    import java.io.File;
    import java.io.*;

    public class FileInOutEx {
     
        public static void main(String[] args) throws IOException{

    File file_Book1 = new File("Book1.txt");

    byte[] bookInfo = "世界是好的\t 350.0\t Friedman\t".getBytes();

    file_Book1.createNewFile();

    FileOutputStream fos = new FileOutputStream(file_Book1);

    fos.write(bookInfo);

    fos.close();

    FileInputStream fis = new FileInputStream(file_Book1);

    byte[] byt = new byte[1024];

    System.out.println("书籍名称\t 价格\t 作者\t");

    System.out.println("---------------------------------------");

    int i = fis.read(byt);



    System.out.print(new String(byt,0,i));

    fis.close();

    }
    }