Results 1 to 12 of 12
Thread: Accessing metadata of files
- 09-19-2010, 10:26 AM #1
Member
- Join Date
- Aug 2010
- Posts
- 40
- Rep Power
- 0
Accessing metadata of files
Hi!
I'm developing a simple file manager. So, I have two components: JTree & JTable. When I open some folder in JTree, then JTable is updated according to the content of that folder. JTable contains 3 columns: file_type, file_name, file_bytes. The code works correctly.
Now I need to add some more columns to describe each file in JTable, e.g. file_author, file_description, file_link. How could I assign/read these data to/from files? Should I use metadata?
- 09-19-2010, 10:33 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 09-19-2010, 10:43 AM #3
Member
- Join Date
- Aug 2010
- Posts
- 40
- Rep Power
- 0
Thank you, it's a pity:(
Is it possible to solve this problem without metadata? Maybe, I could add some tags "@file_description:..." at the top of the file? In this case, I don't know how to deal with "pdf" files...
- 09-19-2010, 10:55 AM #4
Member
- Join Date
- Aug 2010
- Posts
- 40
- Rep Power
- 0
For instance, here Managing Metadata (File and File Store Attributes) (The Java™ Tutorials > Essential Classes > Basic I/O) I see some information about metadata. Could I use it in my case?
- 09-19-2010, 11:00 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 09-19-2010, 11:13 AM #6
Member
- Join Date
- Aug 2010
- Posts
- 40
- Rep Power
- 0
But what is this: Java Platform, Standard Edition 7 Binary Snapshot Releases? Isn't it JDK 7 installation? I've just installed Java SE Development Kit 7, will try it.
- 09-19-2010, 11:19 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 09-19-2010, 11:23 AM #8
Member
- Join Date
- Aug 2010
- Posts
- 40
- Rep Power
- 0
Ok, thank you. Eh...So, my problem is unsolveable now.
- 09-19-2010, 11:55 AM #9
If this is Windows and the file system is NTFS, you can use alternate streams. Example:How could I assign/read these data to/from files?Otherwise you can save a companion file e.g. for myPDF.pdf you can save a file myPDF.pdf.txt with the metadata. This is not foolproof as it's theoretically possible that a myPdf.pdf.txt text file already exists. Using a long and obscure extension e.g.myPDF.pdf.myMetadata makes the chances of this happening astronomically low.Java Code:import java.io.*; public class AlternateStreamTest { public static void main(String[] args) { File outFile = new File("e:/java/outTest.txt:alternate"); FileOutputStream fos = null; try { fos = new FileOutputStream(outFile); fos.write("The quick brown fox jumps over the lazy dog".getBytes()); } catch (IOException ioe) { ioe.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException ex) { ex.printStackTrace(); } } } File inFile = new File("e:/java/inTest.txt"); outFile.renameTo(inFile); inFile = new File("e:/java/outTest.txt:alternate"); FileInputStream fis = null; try { fis = new FileInputStream(inFile); byte[] b = new byte[1024]; while (fis.available() > 0) { fis.read(b); System.out.println(new String(b)); } } catch (IOException ioe) { ioe.printStackTrace(); } finally { if (fis != null) { try { fis.close(); } catch (IOException ex) { ex.printStackTrace(); } } } } }
Note: in the example above, the alternate stream cannot be viewed in the usual editor (NotePad). Google "NTFS Alternate Streams" for more information.
db
- 09-19-2010, 12:09 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
I didn't know that and I find it a strange feature; I guess an 'alternate stream' can't have another alternate stream, can it?
kind regards,
Jos
- 09-19-2010, 03:34 PM #11
No, only a physical file can have an alternate stream. But a little juggling showed that the alternate stream can be a file that itself has an alternate stream.
This is going to be hard to read :-\dbJava Code:import java.io.*; public class AlternateStreamTest { public static void main(String[] args) throws IOException { File fileOstreamA = new File("e:/java/outA.txt:alt"); FileOutputStream fos = null; try { fos = new FileOutputStream(fileOstreamA); fos.write("The quick brown fox jumps over the lazy dog".getBytes()); } finally { if (fos != null) { try { fos.close(); } catch (IOException ex) { ex.printStackTrace(); } } } File fileO = new File("e:/java/outA.txt"); File fileO2 = new File("e:/java/outS.txt"); File fileO2streamS = new File("e:/java/outS.txt:sub"); fileO.renameTo(fileO2streamS); File fileI2 = new File("e:/java/inS.txt"); fileO2.renameTo(fileI2); File fileI2streamS = new File("e:/java/inS.txt:sub"); File fileI = new File("e:/java/outA.txt"); fileI2streamS.renameTo(fileI); File fileIstreamA = new File("e:/java/outA.txt:alt"); FileInputStream fis = null; try { fis = new FileInputStream(fileIstreamA); byte[] b = new byte[1024]; while (fis.available() > 0) { fis.read(b); System.out.println(new String(b)); } } finally { if (fis != null) { try { fis.close(); } catch (IOException ex) { ex.printStackTrace(); } } } } }
- 09-19-2010, 05:49 PM #12
Member
- Join Date
- Aug 2010
- Posts
- 40
- Rep Power
- 0
Similar Threads
-
Randomly accessing files
By Java Tip in forum Java TipReplies: 0Last Post: 12-12-2007, 10:46 AM -
Accessing index.dat files
By vissu007 in forum NetworkingReplies: 1Last Post: 07-01-2007, 04:47 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks