Microsoft
Software
Hardware
Network
Question : FileInputStream check if a file is in use
I tried to open a file that's being downloaded using FileInputStream. But it gives me the following errors:
java.io.FileNotFoundExcept
ion: C:\\tmp\jre-7-ea-bin-b93-w
indows-i58
6-13_may_2
010.jar (The process cannot access the file because it is being used by another process)
at java.io.FileInputStream.op
en(Native Method)
at java.io.FileInputStream.<i
nit>(FileI
nputStream
.java:137)
at java.io.FileInputStream.<i
nit>(FileI
nputStream
.java:96)
...
I did try to use File file = new File(NewFile);
and put if (file.canRead()) before I use the FileInputStream. But teh canRead( ) returns true while the FileInputStream failed with above exception.
How can I check if the FileInputStream will work?
Thanks!
Answer : FileInputStream check if a file is in use
when different processes access the file, i think you can use
FileChannel.lock()/FileCha
nnel.tryLo
ck(),
this will obtain a exclusive lock on the File for the JVM process, so other process (download) cannot access it and the other way around.
Random Solutions
Exchange 2003 Account Outlook Mailbox Security
Out of grace periods on Novell
How can I add a total cost for each row that has at least one dynamic checkbox checked?
How do I get inherited properties from a derived interface using Reflection ?
Windows Server 2008 Standard & Exchange 2010 CAL (licensing) Questions
Public IP
Recovering deleted files
How to Specify What Websites can run ActiveX?
word/excel don't show any printers on terminal server, but outlook/notepad/IE/etc work perfectly
Looking for detailed comparisons/recommendation
s as to whether corporations should upgrade from Excel 2003 to Excel 2010 versus 2007