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.

Results 1 to 3 of 3

Thread: Writing string to file

  1. #1
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default What does this error mean

    I am working on this program and I'm almost done but when I try to write a string to a file I get this error:

    java.lang.ArrayIndexOutOfBoundsException: 98

    I'm just wondering what causes this and how you could fix it. Thanks!


  2. #2
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Writing string to file

    When I do this

    	public void write(String key, String password, File data) throws IOException { // Writes the encrypted string to a file.
    		System.out.println(data);
    		out = new BufferedWriter(new FileWriter(data, true));
    		out.write(encrypted(key, password));
    		out.newLine();
    		out.close();
    		System.out.println("Your password was saved successfuly! " + encrypted(key, password));
    	}
    }

    I get this error
    java.lang.ArrayIndexOutOfBoundsException: 98
    and the value of "data" is this (which is correct):
    /home/newbi3/.encrypter/encrypted.log

    But when I do this
    	public void write(String key, String password) throws IOException { // Writes the encrypted string to a file.
                    File data = new File("/home/newbi3/.encrypter/encrypted.log");
    		System.out.println(data);
    		out = new BufferedWriter(new FileWriter(data, true));
    		out.write(encrypted(key, password));
    		out.newLine();
    		out.close();
    		System.out.println("Your password was saved successfuly! " + encrypted(key, password));
    	}
    }

    I get no errors and the value of "data" is still the same. Why is this?

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: What does this error mean

    The exception's name says it all - there is an array index that is out of bounds. This occurs when attempting to access the index of an array or similar data type that does not exist (is smaller than zero, or larger than the array (-1)). This is explained in the API docs: http://docs.oracle.com/javase/6/docs...Exception.html

    Edit: And please read the forum rules - don't duplicate the same question. I have merged your two threads.
    Last edited by copeg; July 10th, 2012 at 08:39 AM.

Similar Threads

  1. counting the values in input file and and writing the output to a file
    By srujirao in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 8th, 2012, 02:48 PM
  2. Password writing file
    By SilentNite17 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 5th, 2012, 10:07 PM
  3. new line in file writing
    By deependeroracle in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: January 30th, 2012, 10:06 AM
  4. [SOLVED] Writing integers to a file
    By dubois.ford in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 15th, 2010, 06:18 PM
  5. Writing Output To New File
    By Scottj996 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: January 6th, 2010, 07:25 PM

Tags for this Thread