They can be different because the new File(name).length()
always checks the path given. When you use FileInputStream
, you attach to that file regardless of what happens to it.
For example, in Linux you can rename, replace or delete a file which is in use. The FileInputStream
will continue to give the original file's size whereas the File
will give you what replaced it, if any.