How to solve this?
File f=new File("d:/tester.txt");
long size=f.length(); // returns the size in bytes
char buff[]=new char[size]; // line of ERROR
// will not accept long in it's argument
// I can't do the casting (loss of data)
Is it possible to use size
as the length of buff
without the loss of data?
If yes how can i use it?
My second question is :
Why i am not getting the actual number of bytes?
This is the program :
import java.io.*;
class tester {
public static void main(String args[]) {
File f=new File("c:/windows/system32/drivers/etc/hosts.File");
long x=f.length(); // returns the number of bytes read from the file
System.out.println("long-> " + x );
}
}
The output is long-> 0
,but obviously it is not so.Why do i get this result?