473,396 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

error: "unreachable statement in File.close();"

natie
5
I have the following code which is a method that displays the content of a file with the name "File"

Expand|Select|Wrap|Line Numbers
  1.  public void DisplayAll()throws IOException
  2.  
  3.     {
  4.                try
  5.             {DataInputStream F = new DataInputStream(new FileInputStream("File"));
  6.             {
  7.                 for(;;)
  8.                 {
  9.                 System.out.println(F.readUTF());
  10.                 System.out.println(F.readInt());
  11.                 System.out.println(F.readInt());
  12.                 }
  13.  
  14.               }
  15.  
  16.             F.close();
  17.             }catch(EOFException eof){}
  18.  
  19.        }
  20.  
  21.  
the error is: "unreachable statement" at the "F.close". what I'm supposed to do?
Jan 16 '11 #1
1 3399
horace1
1,510 Expert 1GB
in line 7
Expand|Select|Wrap|Line Numbers
  1.     for(;;)
  2.        ...
  3.  
you have an infinite loop, i.e. there is no exit condition so the F.close() in line 16 can never be reached.
there should be an exit condition for the loop - I would suggest putting the F.close() in the catch EOFException(), e.g.
Expand|Select|Wrap|Line Numbers
  1.         DataInputStream F=null;
  2.         try
  3.             {
  4.              F = new DataInputStream(new FileInputStream("File"));
  5.              for(;;)
  6.                 {
  7.                 System.out.println(F.readUTF());
  8.                 System.out.println(F.readInt());
  9.                 System.out.println(F.readInt());
  10.  
  11.             }       
  12.          }          
  13.          catch(EOFException eof) { F.close();}
  14.          catch(IOException e) { System.out.println(e) ;}
  15.  
  16.  
Jan 16 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Help Needed | last post by:
There is an ASP page in my site which sometimes gives file not found error. This page which is suppossedly missing exists on the server and available most of the time. But sometimes out of the...
1
by: Chris | last post by:
I have seen the posts on various places on the internet about .NET framework mismatch issues and I don't think that is my problem. ; ) When I execute the following C++.NET code: String...
6
by: Dave H | last post by:
You'll have to excuse me if I don't know what I'm talking about, but I'm new to webservices. I'm attempting to compile a C# file with csc /r:dmcorex.dll...
0
by: Nic Butler | last post by:
Hi, I've got a win form app that takes an arbitrary file from the local drive, calls a webservice function, passing the file's byte array plus an number of other params. About half the time I...
2
by: Kel Good | last post by:
I have a component which I want to register for COM interop. At the top of my code file I have the following lines. Imports System.Reflection <Assembly: AssemblyKeyFileAttribute("myKey.snk")>...
10
by: Eric | last post by:
Hello, I have some server side includes on a Classic asp page that look something like: <!-- #include virtual="/includes/file1.asp"--> <!-- #include virtual="/includes/file2.asp" --> <!--...
6
by: dthompson | last post by:
I have written a service designed to run on 2003 Servers, in development it works 100% on my Windows XP system. Once deployed to 2003 I keep getting the same error (File Not Found, error 53)...
3
by: DontB3 | last post by:
Hi, I'm new in this forum, and i hope someone can help. I'm creating an automatic application that transfer a database from Access -> DBF -> Oracle. When My App try to execute Insert SQL...
1
by: jimmylee | last post by:
Hi All, Please help me . I am getting aspSmartUploadfile error while uploading file I have already instrall aspSmartUpload.dll and aspSmartUploadutil.dll. how to solve this error. thanks....
8
by: dougancil | last post by:
I'm a new vb.net user and am creating a page on a Windows 2003 Server. When I try to view the page with a browser I get the following error: Parser Error Message: The file...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.