Thread: File output in JAVA (not C++ sorry to offend;))

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    5

    File output in JAVA (not C++ sorry to offend;))

    Hey sorry know this is strictly a c/c++ board but you guys seem helpfull so maybe u can help with some java to, I have the following code
    Code:
    public static void outputFile(double[][] y)
    	{
    		// Declare output file
    		File file = new File("output.txt");
    
    		try{
    			// Declare file output stream
    			FileWriter fos = new FileWriter(file);
    
    			for(int i = 0; i < y.length; i++)
    			{
    				char yc = (char)y[i][1];
    				fos.write(yc);
    			}
    			// Close the file
    			fos.close();
    		   }
    		catch(IOException ex)
    		{
    			System.out.println(ex.getMessage());
    		}
    
    	}
    and im getting an array index out of bounds excpetion. Cant figure out why tho as the for loop is for the length of the array and i write one element of the array each loop iteration (or so i believe), any ideas?

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    try checking y[i].length - i guess its 0 - thus y[i][1] fails
    signature under construction

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    5
    ooops cheers, what a duffus, been using matlab too much lately with its stupid arrays starting at 1 bussiness

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 01:11 AM
  3. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  4. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM
  5. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 03:28 PM