Jayakrishnan GK
Jayakrishnan GK

Reputation: 737

How to get filesize of file generated using XMLStreamWriter?

I am using XMLStreamWriter class from StAX to generate XML file from a java program. I followed this tutorial and the XMLFile is getting generated correctly. How do I get the size of the file that has been generated ?

Upvotes: 0

Views: 409

Answers (1)

A4L
A4L

Reputation: 17595

Using the method File#length()

Returns: The length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist. Some operating systems may return 0L for pathnames denoting system-dependent entities such as devices or pipes.

File out = new File("data\\output2.xml");
System.out.printf("file size: %d bytes%n", out.length());

With java 1.7 you can use the static method Files#size (note: Files)

Path path = Paths.get("data\\output2.xml");
System.out.printf("file size: %d bytes%n", Files.size(path));

Upvotes: 1

Related Questions