Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!postnews.google.com!j37g2000prh.googlegroups.com!not-for-mail From: KevinSimonson Newsgroups: comp.lang.java.programmer Subject: Re: Trying to Understand Purpose of a Catch Block for IOException in the Presence of One for FileNotFound Date: Fri, 12 Aug 2011 11:19:40 -0700 (PDT) Organization: http://groups.google.com Lines: 114 Message-ID: References: <0f7fb5c4-6031-4778-9ef7-de757bbdda39@m5g2000prh.googlegroups.com> NNTP-Posting-Host: 216.49.181.254 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1313173650 1955 127.0.0.1 (12 Aug 2011 18:27:30 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 12 Aug 2011 18:27:30 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: j37g2000prh.googlegroups.com; posting-host=216.49.181.254; posting-account=gsXmKQkAAADuyNfZpkeBrCCcqQvlDvn9 User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 1.1.4322; InfoPath.2; .NET4.0E; .NET4.0C),gzip(gfe) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7051 On Aug 12, 9:57=A0am, markspace <-@.> wrote: > On 8/12/2011 8:39 AM, KevinSimonson wrote: > > > I would appreciate any information anyone can give me on this. > > I'm with Knute here: =A0tl;dr, Show us the code! I've actually written a number of different programs trying to find something that I can run that will throw an exception that is a but not a . I've tried to open a file for input when I don't have read access to the file. I've tried to open a file for output when the file exists and I don't have write access to the file. I've opened a file for input, done a "chmod u-r " while the program's running, and then tried to close the file. I've opened a file for output, done a "chmod u-w " while the program's running, and then tried to close the file. Do any of you want me to dig up some of those files? Most recently I tried writing a Java program that opens a file but then closes it without writing anything to it, that results in an empty file, and then opens the same file and tries to read a line from it. But that results in a getting thrown, not an . I don't think that file will help anyone. Perhaps the best bet would be one I wrote back on 8 August: import java.io.IOException; import java.io.FileNotFoundException; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.File; import java.io.FileWriter; import java.io.BufferedWriter; import java.io.PrintWriter; import java.util.Scanner; public class Cf { private static void prompt ( BufferedReader userInput , String prmpt) { System.out.print( prmpt + "? "); try { userInput.readLine(); } catch (IOException excptn) { } } public static void main ( String[] arguments) { if (arguments.length =3D=3D 2) { int lineCount =3D 0; boolean srcOpnd =3D false; try { BufferedReader usrInpt =3D new BufferedReader( new InputStreamReader( System.in)); prompt( usrInpt, "Construct source"); Scanner source =3D new Scanner( new File( arguments[ 0])); srcOpnd =3D true; prompt( usrInpt, "Construct destination"); PrintWriter dstntn =3D new PrintWriter ( new BufferedWriter( new FileWriter( arguments[ 1]))); String textLine; for (;;) { prompt( usrInpt, "Call "); if (! source.hasNextLine()) { break; } prompt( usrInpt, "Read line"); textLine =3D source.nextLine(); prompt( usrInpt, "Write line"); dstntn.println( textLine); lineCount++; } prompt( usrInpt, "Close files"); dstntn.close(); source.close(); prompt( usrInpt, "All done"); } catch (FileNotFoundException excptn) { System.out.println(); System.out.println( "Couldn't open file!"); System.out.println( " =3D=3D " + srcOpnd + '.'); } catch (IOException excptn) { System.out.println(); System.out.println( "I/O problem with file!"); System.out.println( " =3D=3D " + srcOpnd + '.'); } } else { System.out.println( "Usage is\n java Cf "); } } } Functionally, it copies the contents of a file to another file, but it stops at every significant part of the process and prompts for user input. It doesn't _require any information_ from the user; all the user has to do is hit the key; all it does is let the user delay execution of certain parts of the program until s/he has changed permissions on the original file or the copy if s/he chooses to do so. So try running this program and doing various things to the two files. If you can find something that actually generates a , please, _please_, let me know what you did! Kevin Simonson