0

I have a question for you.

I have a XML file (or CSV file):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<City>
    <Code>LO</Code>
    <Name>London</Name>
</City>

and I want to extract the additional information (for example, Author, Description, Creator, Comments, Format, ContentType etc.) from it in Java Code.

I read this similar question, but the extracting is from Excel file to Java Code: How to set Author name to excel file using poi

I would like to get in output the additional information (System.out.println(getAuthor) for example), if I give in input the filename (for example, test.csv or test.xml).

Who can help me?

Community
  • 1
  • 1
Musich87
  • 562
  • 1
  • 12
  • 31
  • Can you update your example XML to include the tags you wish to extract? – user184994 Jun 12 '14 at 19:02
  • I want to extract the additional information, which aren't present in the example XML, but are present if you right-click of the mouse on the file and you choose "Properties". There are information as "NameFile", "TypeFile", "DimensionFile", "CreatorFile" and other. – Musich87 Jun 12 '14 at 19:09

1 Answers1

1

Those information are not inside the file itself, which only contains its content (like your XML string). They depend on the operating system (which one are you using?). And it is a little bit unclear what you are looking for. So here is what you mentioned:

Author

Path path = Paths.get("C:/Users/Thomas/workspace_eclipse_java/Test/javassist-3.12.1.GA.jar");
FileOwnerAttributeView owner= Files.getFileAttributeView(path, FileOwnerAttributeView.class);
System.out.println("owner: " + owner.getOwner().getName());

Description

I have no idea what this should be. Never saw this on Windows or Linux.

Creator

Do you mean the Author again?

Comments

I have no idea what this should be. Never saw this on Windows or Linux.

Format

Check the file extension

ContentType

Check the file extension or take a look inside.

Generally

Generally you can check what is available by this:

FileSystem fileSystem = FileSystems.getDefault();
Set<String> fileSystemViews = fileSystem.supportedFileAttributeViews();
for (String fileSystemView : fileSystemViews)
    System.out.println(fileSystemView);
Thomas Uhrig
  • 30,811
  • 12
  • 60
  • 80
  • Thanks Thomas. How I said before, I want to extract the additional information, which aren't present in the example XML, but are present if you right-click of the mouse on the file and you choose "Properties". There are information as "NameFile", "TypeFile", "DimensionFile", "CreatorFile" and other. For example, if you right-click of the mouse on the Excel File and you choose "Properties", you can notice a list of property as Author, Comments etc. I would like the same property also CSV or XML file. Sorry, but I don't speak English!!! – Musich87 Jun 12 '14 at 19:32
  • Thanks! I have used FileOwnerAttributeView and BasicFileAttributeView to get this information. In particular, I have used "readAttributes" method of the BasicFileAttributeView class to get "lastModifiedTime" and size of the file and "FileOwnerAttributeView" method to get owner of the file. – Musich87 Jun 13 '14 at 08:42