public void code() { try { bw = new BufferedWriter(new FileWriter(new File(new StringBuilder().append(filename).append("-coded.txt").toString()))); String read; while((read = br.readLine()) != null) { for(int x = 0; x <= read.toCharArray().length; x++) list.get(read.charAt(x)); } } bw.close(); } catch(IOException e) { e.printStackTrace(); } } [ERROR] Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 4 at java.lang.String.charAt(libgcj.so.70) at Decoder.code(Decoder.java:66) at Decoder.(Decoder.java:46) at Decoder.main(Decoder.java:80)