代码很简单:
import java.io.*;
public class Myjava{
   public static void main(String args[]){
       try{
        FileOutputStream fos = new FileOutputStream("D:\\123.txt");
        DataOutputStream dos = new DataOutputStream(fos);
        dos.writeDouble(3.1415926575);
       }catch(Exception e){}
       System.out.println("可以了");
   }
}运行完之后,123.txt文件的内容为什么是乱码啊?怎么才能正常显示?

解决方案 »

  1.   

    以二进制写入去的
    不要漏 dos.close();fos.close();
      

  2.   


    public static void main(String[] args) {
    OutputStream os=null;
    try {
    os=new FileOutputStream("d:/123.txt");
    os.write("1234567学习java IO".getBytes());
    os.close();
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
      

  3.   


    public static void main(String[] args) {
    OutputStream os=null;
    try {
    os=new FileOutputStream("d:/123.txt");
    os.write("1234567学习java IO".getBytes());
    os.close();
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
      

  4.   

    文本操作一般用Reader 和 Writer 
      

  5.   

    文本操作一般用Reader 和 Writer  
      

  6.   

    reader和writer估计是太老了吧  我都没用过 估计我现在用的是新io