*Thread closed*
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
*Thread closed*
In fact a FileNotFoundException is thrown under all sorts of circumstances (access rights, invalid syntax) so we don't really now what the problem is.try { scanner = new Scanner(new File("/Users/YourName/Desktop/originalFile.txt")); //This is a mac directory } catch (FileNotFoundException e) { //If the file does not exist, show a fancy output System.out.println("This file does not exist!"); /* *If you want to, you can also add "e.printStackTrace();", but we already know *what the problem is. printStackTrace(); shows what the error is. "e" is the exceptions name. */ }
If you are going to include exception logic in the example the catch block should probably return, otherwise there will be a NullPointerException later.
Did you mean to write the altered words to the output file? Otherwise the FileWriter isn't doing anything, and the converted words are never used.
Cronus (June 25th, 2013)
This is just a half done code, I wrote it quickly, I'll modify it. You learn something new every day!
I hoped you wouldn't mind that I commented. (I assumed that or you wouldn't have posted it publicly.)
I don't mind at all, I'm actually glad you optimized the code. Congrats on getting 900 posts!