Results 1 to 2 of 2

Thread: Weather Program

  1. #1
    PowTecH is offline Member
    Join Date
    Apr 2013
    Rep Power

    Default Weather Program

    Hello kind of hung up on a part of my code and was wondering if anyone could help me out
    Java Code:
    import java.util.*;
    public class tempProgram
    	 * @param args
    	public static void main(String[] args) throws FileNotFoundException
    		Scanner console = new Scanner(;
    		String inputFileName = "";
    		System.out.print("Please enter file name");
    		inputFileName =;
    		File inputFile = new File(inputFileName);
    		Scanner in = new Scanner(inputFile); 
    		PrintWriter out = new PrintWriter("outputFileName.txt"); 
    i need to use a try catch to insure that the input file is correct/available
    i tried a couple different ways to do it but each time i tried it failed really badly and i confused myself, if seeing all of the code would be of help to anyone just let me know.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Rep Power

    Default Re: Weather Program

    Best practices are to enclose only the code that can throw an exception with a try/catch statement. The first thing you need to do is identify what lines of code may throw exceptions. Reading the API will help or the lazy way is to just compile your code and the compiler will tell you (as long as you delete the throws clause on the main method).

Similar Threads

  1. Accessing weather from internet
    By abdul_053 in forum Advanced Java
    Replies: 2
    Last Post: 01-17-2013, 07:27 PM
  2. Replies: 4
    Last Post: 11-21-2012, 01:19 PM
  3. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  4. Replies: 0
    Last Post: 03-23-2011, 03:46 AM
  5. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts