title: Write to a file with a specific encoding in Java
body: <p>This <em>might</em> be related to my <a href="https://stackoverflow.com/questions/39262555/interpret-a-string-from-one-encoding-to-another-in-java/39262819?noredirect=1#comment65861448_39262819">previous question</a> (on how to convert "fÃ¶r"  to "för")</p>
  
  <p>So I have a file that I create in my code. Right now I create it by the following code:</p>
  
  <pre><code>FileWriter fwOne = new FileWriter(wordIndexPath);
  BufferedWriter wordIndex = new BufferedWriter(fwOne);
  </code></pre>
  
  <p>followed by a few</p>
  
  <pre><code>wordIndex.write(wordBuilder.toString()); //that's a StringBuilder
  </code></pre>
  
  <p>ending (after a while-loop) with a </p>
  
  <pre><code>wordIndex.close();
  </code></pre>
  
  <p>Now the problem is later on this file is huge and I want (need) to jump in it without going through the entire file. The <code>seek(long pos)</code> method of <code>RandomAccessFile</code> lets me do this. </p>
  
  <p><strong>Here's my problem</strong>: The characters in the file I've created seem to be encoded with UTF-8 and the only info I have when I seek is the character-position I want to jump to. <code>seek(long pos)</code> on the other hand jumps in bytes, so I don't end up in the right place since an UTF-8 character can be more than one byte.</p>
  
  <p><strong>Here's my question</strong>: Can I, when I write the file, write it in ISO-8859-15 instead (where a character is a byte)? That way the <code>seek(long pos)</code> will get me in the right position. Or should I instead try to use an alternative to <code>RandomAccessFile</code> (is there an alternative where you can jump to a character-position?) </p>