你是要用什么打开???
记事本程序吗???
还是要用JAVA读出来???

解决方案 »

  1.   

    FileInputStream file=new FileInputStream("log.txt");
          boolean eof=false;
          int count=0;
          while(!eof){
            int input =file.read();
             System.out.println(input+" ");
             if(input==-1)
               eof=true;
             else
               count++;
          }
          file.close();
          System.out.println("\n Bytes read:"+count);
      

  2.   

    Runtime runtime= Runtime.getRuntime();
                        runtime.exec("aa.txt");
    这个是调可执行的程序的
    用楼上的代码
      

  3.   

    二楼的那个东西怎么能读出什么有实际使用价值的东西呢???
    最基本的也应该写成这样吧???
    [CODE]
    import java.io.*;public class TestFileRead
    {
    public static void main(String[] args) throws Exception
    {
    FileInputStream in = new FileInputStream("log.txt");
    InputStreamReader read = new InputStreamReader(in);
    BufferedReader reader = new BufferedReader(read);

    String line;
    String allContent = "";

    while ((line = reader.readLine()) != null)
    {
    allContent += line + System.getProperty("line.separator");
    //System.out.println(line);
    }
    System.out.println(allContent);
    }
    }
    [/CODE]
      

  4.   

    如果输出的中文字符解码有问题,还可以这么用
    InputStreamReader read = new InputStreamReader(in,"gb2312");//具体的解码格式可以自己定。还有,如果想要更加人性化,可以写成这样:import java.io.*;public class TestFileRead
    {
    private static String fileName = "";
    public static void main(String[] args) throws Exception
    {
    fileName = "log.txt";
    try
    {
    fileName = (args[0].equals(""))? fileName: args[0];
    }
    catch(Exception e)
    {
    System.out.println(e.getMessage());
    System.out.println("没有输入要打开的文件,默认打开的文件是“" + fileName + "”");
    }
    File file = new File(fileName);
    FileInputStream in = new FileInputStream(fileName);
    InputStreamReader read = new InputStreamReader(in);
    BufferedReader reader = new BufferedReader(read);

    String line;
    String allContent = "";

    while ((line = reader.readLine()) != null)
    {
    allContent += line + System.getProperty("line.separator");
    //System.out.println(line);
    }
    System.out.println(allContent);
    }
    }
      

  5.   

    呵呵,刚才没注意,有纰漏了。
    ^O^声明"fileName"时,应该这么写:private static String fileName = "log.txt";去掉:fileName = "log.txt";呵呵。
      

  6.   

    我只是想在按一个按狃的时候打开另一个文件而已 不是在JAVA里要读出文件的内容
      

  7.   

    File file=new File("c:\\a.txt");
    FileInputStream in=new FileInputStream(file);//对他的读操作
    in.read();........FileOutputStream out=new FileOutputStream(file);//写操作
    out.write()............
      

  8.   

    怎么看怎么像《梦里花落知多少》里的“卖女孩儿的小火柴”!!!
    ^O^这样就可以了:public class SxRuntime
    {
    public static void main(String[] args)
    {
    try
    {
    Runtime.getRuntime().exec("notepad.exe SxRuntime.java");
    }
    catch(Exception e)
    {
    System.out.println(e.getMessage());
    }
    }
    }Runtime runtime= Runtime.getRuntime();
                        runtime.exec("aa.txt");