How to describe content of file rar/zip in jtable from url or path directory in java?
I found here and here
But how to open from URL on describe to jtable?
Asked
Active
Viewed 303 times
0

trashgod
- 203,806
- 29
- 246
- 1,045

Muhammad Cahya
- 288
- 4
- 13
-
And what are you going to do if the rar/zip contains folders (with subfolders, .... ). A file structure is typically shown in a `JTree` instead of a `JTable` – Robin Jul 31 '12 at 05:55
-
well, Good Idea, have a references ? – Muhammad Cahya Jul 31 '12 at 07:10
2 Answers
1
I'd use PrpcessBuilder
, shown here, to execute unzip -l
or unrar -l
and parse the output to create my TableModel
. See also How to Use Tables.
1
You need to model the data some how. Maybe a VirtualFile
, this should contain the information you want to display.
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)
Once you've decided on how you want the model to be laid out, you simply supply the modle to the JTable
For more information check out How to use Tables
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
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) {
}
}

MadProgrammer
- 343,457
- 22
- 230
- 366
-
And then, how to open file from URL ? because the type is file, and file not compatible with url type ? – Muhammad Cahya Jul 31 '12 at 05:33
-
Well, if the `URL` is not a reference to a file on the local system you could grab the `URL`'s `InputStream` and copy it locally, then reference the local copy via a `File` object – MadProgrammer Jul 31 '12 at 05:40
-
maybe it will spend a lot of memory, but have a references ? i newbie in java, this is my first project in java – Muhammad Cahya Jul 31 '12 at 07:13