简体   繁体   English

如何从url或path(目录)中描述jtable中文件rar / zip的内容?

[英]How to describe content of file rar / zip in jtable from url or path(directory)?

How to describe content of file rar/zip in jtable from url or path directory in java? 如何在java中的url或path目录中描述jtable中文件rar / zip的内容?
I found here and here 我在这里这里找到
But how to open from URL on describe to jtable? 但如何从URL上打开描述到jtable?

I'd use PrpcessBuilder , shown here , to execute unzip -l or unrar -l and parse the output to create my TableModel . 我使用这里显示的PrpcessBuilder执行unzip -lunrar -l并解析输出以创建我的TableModel See also How to Use Tables . 另请参见如何使用表

You need to model the data some how. 您需要为数据建模一些方法。 Maybe a VirtualFile , this should contain the information you want to display. 也许是一个VirtualFile ,它应该包含你想要显示的信息。

You then need to create a model of the that wraps this data in some meaningful way. 然后,您需要创建一个以有意义的方式包装此数据的模型。 You'll need a TableModel for this purpose (preferably use the Abstract or Default implementation) 为此,您需要一个TableModel (最好使用AbstractDefault实现)

Once you've decided on how you want the model to be laid out, you simply supply the modle to the JTable 一旦您决定了如何布置模型,您只需将模型提供给JTable

For more information check out How to use Tables 有关更多信息,请查看如何使用表

UPDATE UPDATE

You can learn more from the Basic I/O lesson , but here's a (really) basic example of reading the contents of URL to local disk 您可以从Basic I / O课程中了解更多信息,但这是一个(实际)基本示例,将URL的内容读取到本地磁盘

File outputFile = new File("Somefile on disk.rar");
Inputstream is;
OutputStream os;
try {
    is = url.openStream();
    os = new FileOutputStream(outputFile);

    byte[] buffer = new byte[1024];
    int bytesIn = -1;
    while ((bytesIn = is.read(buffer)) != -1) {

        os.write(buffer, 0, bytesIn);

    }

    os.flush();
} catch (IOException exp) {
    exp.printStackTrace();
} finally {
    try {
        is.close();
    } catch (Exception exp) {
    }
    try {
        os.close();
    } catch (Exception exp) {
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM