473,326 Members | 2,113 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,326 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 3393
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:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.