Add to Google Reader or Homepage

Three reasons for

File not found Exception

There are three  reason,for this to be thrown at run-time and the reasons are follows:



"If the given file is not available in the specified location then this error will occur".

As you see,this is the most obvious reason for this exception as indicated by the Exception itself.



public class Example1 
public static void main(String[] args) 
FileReader reader = new FileReader("c:/exam.txt");
BufferedReader br = new BufferedReader(reader);
String strcontent =null;
while ((strcontent = br.readLine()) != null) 
In the above code during the execution of the line BufferedReader br=new BufferedReader(reader); if the file exam.txt is not found in the given location then the following error message will appear.

Error message: c:\exam.txt (The system cannot find the file specified)
        at Method)
        at Source)
        at Source)
        at Source)
        at Example1.main(

This exception can be resolved by giving the correct path of the file or storing the file in the given location.

 Reason 2:

"If the given file is inaccessible, say for an example if it is write protected(i.e, ReadOnly) then you can able to read the file but when you try to modify(write into) the file then this error will occur".


import java.util.*;
class ReadingFiles
public static void main(String args[])
File f=new File("FileOut1.txt");
PrintWriter p=new PrintWriter(new FileWriter(f),true);
p.println("Hello world");
p.println("HI PEOPLE");
PrintWriter p1=new PrintWriter(new FileWriter("FileOut1.txt"),true);

catch(Exception e)


ERROR MESSAGE: FileOut1.txt (Access is denied)
        at Method)
        at Source)
        at Source)
        at Source)
        at ReadingFiles.main(

If you see the statements in BOLD in the above program you can able to understand that after setting the readOnly() flag of that file i have tried to write into that file "again". Thus this exception is thrown saying that "Access is Denied". So an important thing to be noted here is if you try to write into a read only file then this exception will be thrown.


Reason 3:


"In some cases, if the file that you are trying to access for read/write operation  is opened by another program then this error will occur".


import jxl.*;
import jxl.Workbook;
import jxl.write.*;

public class ExcelRead
public  static void main(String args[]) throws Exception
Cell b[]=new Cell[2];
WritableWorkbook wbook12=Workbook.createWorkbook(new File("ExcelRead.xls"));
WritableSheet sheet=wbook12.createSheet("First Sheet",0);
Label l1=new Label(0,1,"Hello");
Label l2=new Label(0,2,"World");

Here what am i trying to do is to write some labels in to the "ExcelRead.xls" file. I thought that this would work fine. But when I execute this program I got this "FileNotFoundException". Later i found that it (ExcelRead.xls) has been opened in MicrosoftExcel Application. So in some cases this kind of errors do occur.


C:\blog>java ExcelRead
Exception in thread "main" ExcelRead.xls (The pro
cess cannot access the file because it is being used by another process)
        at Method)
        at Source)
        at Source)
        at jxl.Workbook.createWorkbook(
        at jxl.Workbook.createWorkbook(
        at ExcelRead.main(


Mina Guirguis said...

There is another reason if you need anministrative authority for this file it will give you the same error

here is my new blog for programming tutorials its still new so I am in for beginners phase but later you might find something useful there

Programming tutorials

Ganesh Bhuddhan said...

I too encountered this error due to administrative reasons, but when writing this post i forget to include that...anyway thanks for reminding me of this reason..

Mina Guirguis said...

No problem we are programming fellows :-) so have you thought about making another post with the way to solve those Exceptions or at least get an understandable error message for them?

arun j said...

If the FileNotFoundException thrown at Runtime, then why we need to write throws Excepeion at compiletime .

For RuntimeExceptions , we will not write throws Exceptions right.. It will compile .
But when there is chance to raise FileNotFoundException that time why we writing throws Exception at compiletime..please clarify the doubt

class ExcepTest{
public static void main(String[] args)
int i=10/0;

Netta Thompson said...

can anyone help with a small server issue - seems to be JAVA

---- Minecraft Crash Report ----
// Ooh. Shiny.

Time: 6/20/15 6:01 AM
Description: Exception in server tick loop

at cpw.mods.fml.common.LoadController.transition(
at cpw.mods.fml.common.Loader.preinitializeMods(
at cpw.mods.fml.server.FMLServerHandler.beginServerLoading(
at cpw.mods.fml.common.FMLCommonHandler.onServerStart(
at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(
at net.minecraft.server.MinecraftServer$
Caused by:
at Source)
at Source)
at net.ilexiconn.llibrary.common.web.WebHelper.downloadTextFile(
at net.ilexiconn.llibrary.common.web.WebHelper.readPastebin(
at net.ilexiconn.jurassicraft.JurassiCraft.init(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at cpw.mods.fml.common.LoadController.sendEventToModContainer(
at cpw.mods.fml.common.LoadController.propogateStateMessage(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at cpw.mods.fml.common.LoadController.distributeStateMessage(
at cpw.mods.fml.common.Loader.preinitializeMods(
... 5 more

A detailed walkthrough of the error, its code path and all known details is as follows:

Netta Thompson said...

part 2

-- System Details --
Minecraft Version: 1.7.10
Operating System: Windows 8.1 (amd64) version 6.3
Java Version: 1.7.0_67, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 1457720784 bytes (1390 MB) / 2225602560 bytes (2122 MB) up to 2863661056 bytes (2731 MB)
JVM Flags: 3 total; -Xmx3G -Xms2G -XX:MaxPermSize=256M
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 76 mods loaded, 76 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized
FML{} [Forge Mod Loader] (server.jar) Unloaded->Constructed->Pre-initialized
Forge{} [Minecraft Forge] (server.jar) Unloaded->Constructed->Pre-initialized

Netta Thompson said...

part 3

appliedenergistics2-core{rv2-stable-5} [AppliedEnergistics2 Core] (minecraft.jar) Unloaded->Constructed->Pre-initialized
CodeChickenCore{} [CodeChicken Core] (minecraft.jar) Unloaded->Constructed->Pre-initialized
ivtoolkit{IvToolkit} [1.2] (minecraft.jar) Unloaded->Constructed->Pre-initialized
NotEnoughItems{} [Not Enough Items] (NotEnoughItems-1.7.10- Unloaded->Constructed->Pre-initialized
OpenComputers|Core{1.0.0} [OpenComputers (Core)] (minecraft.jar) Unloaded->Constructed->Pre-initialized
{000} [CoFH ASM] (minecraft.jar) Unloaded->Constructed->Pre-initialized
betterloadingscreen{1.3.0} [Better Loading Screen] ([1.7.10] BetterLoadingScreen-1.3.0.jar) Unloaded->Constructed->Pre-initialized
securitycraft{v1.7.4.1} [SecurityCraft] ([1.7.10] SecurityCraft v1.7.4.1.jar) Unloaded->Constructed->Pre-initialized
bspkrsCore{6.16} [bspkrsCore] ([1.7.10]bspkrsCore-universal-6.16.jar) Unloaded->Constructed->Pre-initialized
StartingInventory{1.7.10.r03} [StartingInventory] ([1.7.10]StartingInventory-universal-1.7.10.r03.jar) Unloaded->Constructed->Pre-initialized
Treecapitator{1.7.10} [Treecapitator] ([1.7.10]Treecapitator-universal-2.0.4.jar) Unloaded->Constructed->Pre-initialized
appliedenergistics2{rv2-stable-5} [Applied Energistics 2] (appliedenergistics2-rv2-stable-5.jar) Unloaded->Constructed->Pre-initialized
betterrain{0.15} [Better Rain] (betterrain-1.7.2-1.7.10_0.15.jar) Unloaded->Constructed->Pre-initialized
betterrecords{1.7.10-1.1.9} [Better Records] (betterrecords-1.7.10-1.1.9.jar) Unloaded->Constructed->Pre-initialized
betterstorage{} [BetterStorage] (BetterStorage-1.7.10- Unloaded->Constructed->Pre-initialized
BiomesOPlenty{2.1.0} [Biomes O' Plenty] (BiomesOPlenty-1.7.10- Unloaded->Constructed->Pre-initialized
CarpentersBlocks{3.3.6} [Carpenter's Blocks] (Carpenter's Blocks v3.3.6 - MC 1.7.10.jar) Unloaded->Constructed->Pre-initialized
ForgeMultipart{} [Forge Multipart] (ForgeMultipart-1.7.10- Unloaded->Constructed->Pre-initialized
chisel{} [Chisel 2] (Chisel2- Unloaded->Constructed->Pre-initialized

Netta Thompson said...

part 4
CoFHCore{1.7.10R3.0.2} [CoFH Core] (CoFHCore-[1.7.10]3.0.2-262.jar) Unloaded->Constructed->Pre-initialized
lootablebodies{1.3.5} [DrCyano's Lootable Bodies] (CyanosLootableBodies-1.3.5-backport.jar) Unloaded->Constructed->Pre-initialized
eplus{3.0.2-d} [Enchanting Plus] (EnchantingPlus-1.7.10-3.0.2-d.jar) Unloaded->Constructed->Pre-initialized
ThermalFoundation{1.7.10R1.0.0} [Thermal Foundation] (ThermalFoundation-[1.7.10]1.0.0-81.jar) Unloaded->Constructed->Pre-initialized
ExtraUtilities{1.2.5} [Extra Utilities] (extrautilities-1.2.5.jar) Unloaded->Constructed->Pre-initialized
farseek{1.0.8} [Farseek] (Farseek-1.0.8.jar) Unloaded->Constructed->Pre-initialized
FastCraft{1.21} [FastCraft] (fastcraft-1.21.jar) Unloaded->Constructed->Pre-initialized
flansmod{4.10.0} [Flan's Mod] (Flans Mod-1.7.10-4.10.0.jar) Unloaded->Constructed->Pre-initialized
iChunUtil{4.2.2} [iChunUtil] (iChunUtil-4.2.2.jar) Unloaded->Constructed->Pre-initialized
Hats{4.0.1} [Hats] (Hats-4.0.1.jar) Unloaded->Constructed->Pre-initialized
HatStand{4.0.0} [HatStand] (HatStand-4.0.0.jar) Unloaded->Constructed->Pre-initialized
HardcoreQuesting{The Journey (4.2.4)} [Hardcore Questing Mode] (hqm-rexxit-4.2.4.jar) Unloaded->Constructed->Pre-initialized
InventoryPets{1.1.2a} [Inventory Pets] (inventorypets-1.7.10-1.1.2a.jar) Unloaded->Constructed->Pre-initialized
inventorytweaks{1.59-dev-156-af3bc68} [Inventory Tweaks] (InventoryTweaks-1.59-dev-156.jar) Unloaded->Constructed->Pre-initialized
Waila{1.5.10} [Waila] (Waila-1.5.10_1.7.10.jar) Unloaded->Constructed->Pre-initialized
JABBA{1.2.1} [JABBA] (Jabba-1.2.1a_1.7.10.jar) Unloaded->Constructed->Pre-initialized
jcanimation{1.2.4} [JCAnimationAPI] (JurassiCraft-1.4.0bugfix.jar) Unloaded->Constructed->Pre-initialized
llibrary{0.2.0-1.7.10} [LLibrary] (LLibrary-0.2.0-1.7.10.jar) Unloaded->Constructed->Pre-initialized
jurassicraft{1.4.0} [JurassiCraft] (JurassiCraft-1.4.0bugfix.jar) Unloaded->Constructed->Errored
LunatriusCore{} [LunatriusCore] (LunatriusCore-1.7.10- Unloaded->Constructed->Pre-initialized
malisiscore{1.7.10-0.12.2} [MalisisCore] (malisiscore-1.7.10-0.12.2.jar) Unloaded->Constructed->Pre-initialized
malisisdoors{1.7.10-1.8.1} [Malisis' Doors] (malisisdoors-1.7.10-1.8.1.jar) Unloaded->Constructed->Pre-initialized
Mantle{1.7.10-0.3.2.jenkins184} [Mantle] (Mantle-1.7.10-0.3.2.jar) Unloaded->Constructed->Pre-initialized
Mekanism{8.1.4} [Mekanism] (Mekanism-1.7.10- Unloaded->Constructed->Pre-initialized
MekanismGenerators{8.1.4} [MekanismGenerators] (MekanismGenerators-1.7.10- Unloaded->Constructed->Pre-initialized
MekanismTools{8.1.4} [MekanismTools] (MekanismTools-1.7.10- Unloaded->Constructed->Pre-initialized
MineTweaker3{3.0.9B} [MineTweaker 3] (MineTweaker3-1.7.10-3.0.9C.jar) Unloaded->Constructed->Pre-initialized
MTRM{1.0} [MineTweakerRecipeMaker]

Netta Thompson said...

part 5
(MineTweakerRecipeMaker-1.7.10- Unloaded->Constructed->Pre-initialized
numina{} [Numina] (Numina- Unloaded->Constructed->Pre-initialized
powersuits{} [MachineMuse's Modular Powersuits] (ModularPowersuits- Unloaded->Constructed->Pre-initialized
powersuitaddons{} [Modular Powersuit Addons] (ModularPowersuitsAddons- Unloaded->Constructed->Pre-initialized
NetherOres{1.7.10R2.3.0} [Nether Ores] (NetherOres-[1.7.10]2.3.0-12.jar) Unloaded->Constructed->Pre-initialized
ThermalExpansion{1.7.10R4.0.1} [Thermal Expansion] (ThermalExpansion-[1.7.10]4.0.1-182.jar) Unloaded->Constructed->Pre-initialized
OpenComputers{} [OpenComputers] (OpenComputers-MC1.7.10- Unloaded->Constructed->Pre-initialized
harvestcraft{1.7.10i} [Pam's HarvestCraft] (Pam's HarvestCraft 1.7.10i.jar) Unloaded->Constructed->Pre-initialized
Ping{%MOD_VERSION} [Ping] (Ping-1.7.X-1.0.2.B6-universal.jar) Unloaded->Constructed->Pre-initialized
reccomplex{} [Recurrent Complex] (RecurrentComplex- Unloaded->Constructed->Pre-initialized
RedstonePasteMod{1.6.2} [Redstone Paste] (RedstonePasteMod-1.7.10-1.6.2.jar) Unloaded->Constructed->Pre-initialized
Schematica{} [Schematica] (Schematica-1.7.10- Unloaded->Constructed->Pre-initialized
Stackie{} [Stackie] (Stackie-1.7.10- Unloaded->Constructed->Pre-initialized
streams{0.1.4} [Streams] (Streams-0.1.4.jar) Unloaded->Constructed->Pre-initialized
supercraftingframe{} [Super Crafting Frame] (supercraftingframe- Unloaded->Constructed->Pre-initialized
Sync{4.0.0} [Sync] (Sync-4.0.0.jar) Unloaded->Constructed->Pre-initialized
TConstruct{1.7.10-1.8.5.build957} [Tinkers' Construct] (TConstruct-1.7.10-1.8.5.jar) Unloaded->Constructed->Pre-initialized
ThermalDynamics{1.7.10R1.0.0} [Thermal Dynamics] (ThermalDynamics-[1.7.10]1.0.0-122.jar) Unloaded->Constructed->Pre-initialized
TMechworks{} [Tinkers' Mechworks] (TMechworks-1.7.10- Unloaded->Constructed->Pre-initialized
tradeboothmod{} [Trade Booth Mod] (tradebooth. Unloaded->Constructed->Pre-initialized
WR-CBE|Core{} [WR-CBE Core] (WR-CBE-1.7.10- Unloaded->Constructed->Pre-initialized
WR-CBE|Addons{} [WR-CBE Addons] (WR-CBE-1.7.10- Unloaded->Constructed->Pre-initialized
WR-CBE|Logic{} [WR-CBE Logic] (WR-CBE-1.7.10- Unloaded->Constructed->Pre-initialized
McMultipart{} [Minecraft Multipart Plugin] (ForgeMultipart-1.7.10- Unloaded->Constructed->Pre-initialized
aobd{2.6.2} [Another One Bites The Dust] (AOBD-2.6.2.jar) Unloaded->Constructed->Pre-initialized
IguanaTweaksTConstruct{1.7.10-} [Iguana Tinker Tweaks] (IguanaTinkerTweaks-1.7.10-2.1.5.jar) Unloaded->Constructed->Pre-initialized
ForgeMicroblock{} [Forge Microblocks] (ForgeMultipart-1.7.10- Unloaded->Constructed->Pre-initialized
AE2 Version: stable rv2-stable-5 for Forge
CoFHCore: -[1.7.10]3.0.2-262
ThermalFoundation: -[1.7.10]1.0.0-81
Mantle Environment: Environment healthy.
NetherOres: -[1.7.10]2.3.0-12
ThermalExpansion: -[1.7.10]4.0.1-182
TConstruct Environment: Environment healthy.
ThermalDynamics: -[1.7.10]1.0.0-122
Profiler Position: N/A (disabled)
Is Modded: Definitely; Server brand changed to 'fml,forge'
Type: Dedicated Server (map_server.txt)

Netta Thompson said...

sorry about the 5 parts, but I wanted all to be seen so my issue could be solved.

Niket Agrawal said...

what is the solution to reason 3 ,,, i am facing similar issue related to reason 3 .

Naviya Nair said...

Great and Useful Article.

Online Java Course

Java Online Training

Java Course Online

J2EE training

online J2EE training

Best Recommended books for Spring framework

Java Interview Questions

Java Training Institutes in Chennai

Java Training in Chennai

J2EE Training in Chennai

java j2ee training institutes in chennai

Java Course in Chennai

حسام داود said...

شركة تسليك مجاري المطبخ بالرياض
شركة تسليك مجارى الحمام بالرياض
level تسليك المجاري بالرياض
افضل شركة تنظيف بالرياض
تنظيف شقق بالرياض
شركة تنظيف منازل بالرياض
شركة غسيل خزنات بالرياض
افضل شركة مكافحة حشرات بالرياض
رش مبيدات بالرياض
شركة تخزين عفش بالرياض
شركة تنظيف مجالس بالرياض
تنظيف فلل بالرياض
ابى شركة تنظيف بالرياض

Post a Comment

java errors and exceptions © 2010 | Designed by Chica Blogger | Back to top