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
How to configure a VPN on a Cisco 1811
IT Information
Can not send email in SBS 2003
Cannot install ISA 2006, get error “A Connection to the specified Configuration Storage Server"
How to format a message in javascript
Logshipping is failing when SQL Server 2008 cluster is failed over
Exchange OAB
Creat textbox(s) in Excel to enter 3 sets of numbers and then store them joined in one cell
Can't Uninstall Exchange Server 2007 SP1 from 2008 server R2
How to diagnose and fix a messed up keyboard