用什么类及方法读取一个文件中的内容??

解决方案 »

  1.   

    java.io.File file=new java.io.File(path);java.io.FileReader reader=new java.io.FileReader(file);reader.read();
    就可以了。
    关于详细的使用方法,看JDK API文档。
      

  2.   

    private static void  fileread() throws IOException { Properties props = new Properties();
    InputStream is = new FileInputStream("./conf/jdbc.properties");
    props.load(is);
    } /**
     * 读取
     *
     * @param key
     * @return
     * @throws IOException
     */
    public  static  String getProperties(String key) throws IOException { fileread(); return props.getProperty(key, ""); } /**
     * 写入
     *
     * @param key
     * @param value
     * @throws IOException
     */
    public static void  setProperties(String key, String value)
    throws IOException { fileread(); props.setProperty(key, value); }再给你解释一下~它以“=”为参照
      

  3.   

    lz,首先要说明你要读取的文件的类型,才好给你写代码啊!是.ini?.xml?.perperties?.txt?
    楼上说的是读取.perperties文件的方法!不知道你要读的是什么文件!
      

  4.   

    在补充一下.properties文件是以key,value的形式出现的!我上面单词写错了,应该是properties!
      

  5.   

    看什么格式的文件吧?
    详细的可以询问success_dream
      

  6.   

    FileInputStream + BufferedReader
      

  7.   

    fulong258(【轰隆隆】) :
    你写的方法不能读.xml,.ini文件!读这两种文件都有自己的方法的!因为.xml,.ini文件的文件结构和properties,txt文件是不同的!