通过java从web服务器下载文件 我想从web服务器下载临时文件 下面是我尝试过的代码,但我只得到输出文件中编写的HTML内容 但是url路径包含712个.gz格式的文件

通过java从web服务器下载文件 我想从web服务器下载临时文件 下面是我尝试过的代码,但我只得到输出文件中编写的HTML内容 但是url路径包含712个.gz格式的文件,java,Java,这是我正在使用的代码: import java.io.*; public class SampleFile{ public static void main(String args[]) throws IOException{ BufferedInputStream in = new BufferedInputStream(new java.net.URL("http://xxx:9080/xxx/xxx/xxx/xxx/xxx.jsp?file=/apps/WasAp

这是我正在使用的代码:

import java.io.*;

public class SampleFile{
    public static void main(String args[]) throws IOException{
        BufferedInputStream in = new BufferedInputStream(new java.net.URL("http://xxx:9080/xxx/xxx/xxx/xxx/xxx.jsp?file=/apps/WasApps/xxx/templogs/xxx.log.xxx_Server1.2012-04-01.gz").openStream());
        FileOutputStream fos = new FileOutputStream("LocalPath\\koushik.txt");
        BufferedOutputStream bout = new BufferedOutputStream(fos,1024);

        int x=0;
        byte[] data = new byte[1024];
        while((x=in.read(data,0,1024))>=0) {
            bout.write(data,0,x);
        }

        bout.close();
        in.close();
    }
}

在浏览器中弹出该URL,然后查看您得到的响应。我怀疑这会是你所期望的。另外,请在发布到在线论坛时格式化您的代码,您会惊讶于收到的回复数量。您能否详细说明“url路径包含712个.gz格式的文件”的含义?感谢您的回复…我的问题现在解决了,我尝试的是,我刚刚打开了要在服务器上以可读文本格式下载的文件,并在浏览器中使用该url进行下载,下载效果良好。