我要不断读取某个文件,第一次读取下来是正确的,当我要读取的文件中的值改变时,结果还是第一次读取的结果,不知是什么原因,那位大侠来帮一下啊

解决方案 »

  1.   

    关了
    URL url;
    BufferedReader reader;
    String line = "";

    StringBuffer strBuf = new StringBuffer();

    try
    {
    // ファイルからデータを取得
    url    = new URL( "http://" + GuiEnvironment.getHostName() + "/" + dir + "/" + fileKind );
    reader = new BufferedReader( new InputStreamReader( url.openStream() ) );
    while( ( line = reader.readLine() ) != null ) 
    {
    if( line.length() > 0 ) 
    {
    strBuf.append( line.trim() );
    }
    }
    reader.close();

    if( "".equals( strBuf.toString() ) )
    {
    // error( fileKind );
    return;
    }
    }
    catch( Exception e ) 
    {
    error( fileKind );
    return;
    }
    这是其中的一部分代码,那位看看有什么问题吗?
      

  2.   


     public static String getURLContent(String urlString, String encoding) {
        if (urlString == null || "".equals(urlString.trim()))
            return null;    StringBuffer content = new StringBuffer();
        try {
            // 新建URL对象
            URL url = new URL(urlString);
            InputStream in = new BufferedInputStream(url.openStream());
            InputStreamReader theHTML = new InputStreamReader(in,
                encoding != null ? encoding : "gb2312");
            int c;
            while ((c = theHTML.read()) != -1) {
            content.append((char) c);
            }
        }
        // 处理异常
        catch (MalformedURLException e) {
            System.err.println(e);
        } catch (IOException e) {
            System.err.println(e);
        }
        return content.toString();
        }能运行的http://topic.csdn.net/u/20110921/14/0787740f-fdc3-48d5-aeda-f41d741c82ea.html
      

  3.   

    缓存的原因了
    url后面拼一个   ?math.random()试一下
      

  4.   

    典型的线程问题,Buffer读取缓冲区,值变了缓冲内容没变。刷新浏览器
      

  5.   

    刷新不可以的,我是把软件放在浏览器里显示的,还有上面说的在url后添加?math.random(),我添上之后就什么都不显示啦,我是这样添加的
    url    = new URL( "http://" + GuiEnvironment.getHostName() + "/" + dir + "/" + fileKind+"?&" + Math.random() );
    那位高人指点一下啊