The File class is just a representation of a pathname or filename in the file system. It doesn't have anything to do with the contents of the file.
Your second piece of code will not compile, because class java.io.DataOutputStream does not have a constructor that takes a java.io.File as the argument. You could have discovered that quickly by writing a small program yourself.