解决方案 »

  1.   

    把你写入磁盘文件的代码贴出来看看
    比如这样就可以
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.UnsupportedEncodingException;public class FileStreamTest {
    public static void main(String args[]) throws UnsupportedEncodingException, IOException{
    String content="输入整数\n55\n输入浮点数\n15.2\n输入布尔量\ntrue";
    String path="d:"+File.separator+"test.txt";
    writeToTxt(content,path);
    }

    public static void writeToTxt(String content,String path) throws UnsupportedEncodingException, IOException{
    FileOutputStream fos = new FileOutputStream(path);
    fos.write(content.getBytes("UTF-8"));
    fos.flush();
    fos.close();
    }
    }
      

  2.   

    用PrintStream处理字符很方便public class Demo{
        public static void main(String[] args) throws FileNotFoundException {
            PrintStream ps = new PrintStream("d:/test.log");
            Scanner scanner = new Scanner(System.in);
            while(true){
                System.out.println("请输入: ");
                String a = scanner.nextLine();
                if ("quit".equalsIgnoreCase(a)){
                    System.out.println("退出");
                    break;
                }
                ps.println(a);
            }
        }
    }
      

  3.   

    import java.io.*;
    public class File4 {
    public static void main(String[] args) throws IOException{
    InputStreamReader iin=new InputStreamReader  (System.in);
    BufferedReader bin=new BufferedReader(iin);
    File file1=new File("F:\\dataFile.txt");
    try{
    FileOutputStream fout=new FileOutputStream(file1);
    DataOutputStream dout=new DataOutputStream (fout);
    System.out.println("输入整数");
    int i=Integer.parseInt(bin.readLine());
    System.out.println("输入浮点数");
    float f=Float.parseFloat(bin.readLine());
    System.out.println("输入布尔量");
    boolean b=Boolean.parseBoolean(bin.readLine());
    dout.writeInt(i);
    dout.writeFloat(f);
    dout.writeBoolean(b);
    dout.close();
    }
    catch(FileNotFoundException e){
    System.out.println(e);
    }

    }
    }
    (这个就是源代码)
      

  4.   

    你在4楼贴的源码使用了dout.writeInt(i);   // Writes an int to the underlying output stream as four bytes 按照4个字节流方式写入
    dout.writeFloat(f);
    dout.writeBoolean(b);这些操作不是按照字符写入的,你用字符的方式查看(比如打开notepad++),当然和你的输入不同了
    写入和看到的要一样,那就改为 3楼 按照字符方式写入
      

  5.   

    如果你要按照啊字节流方式写入,那么读取的时候也要按照字节流方式读取,也可以还原成你以前输入的信息。
    DataInputStream 有对应的 readInt(), readFloat() , readBoolean()
      

  6.   

    恩恩,当我读到屏幕上是就能显示我输入的东西,
    整数:55
    浮点数:15.12
    布尔量:false