Just wondering, is there a way of finding out the length of a file without actually reading through until the end of the file ?
Using just pure jdk, so no wfc java stuff
Printable View
Just wondering, is there a way of finding out the length of a file without actually reading through until the end of the file ?
Using just pure jdk, so no wfc java stuff
Try using the File class and the length() method
Oh, and...WFC?? You've gotta be kidding :pCode:import java.io.*;
class Test
{
public static void main(String[] args)
{
try
{
File f = new File("C:\\test.txt");
if (f.exists()) System.out.println(f.length()); //Length of the file in bytes
}
catch(Exception e){}
}
}
:)
Code:File fileName = new File("c:\\autoexec.bat")
try
{
System.out.println(fileName.length());
}
catch (Exception e)
{
e.printStackTrace();
}
if i'm not mistaken :confused: :p
Thank you very much people, I can now put a nice percentage meter in my app :)
Lovely :)
Code:lenOfFile = (new File( "packet.txt" )).length();