Good day! The task is given: you need to encrypt the text from the file (there are no questions here), BUT how to perform character-by-character reading from the file so that I can manipulate these characters in my array (assign a character with a specific index, etc.).

Suppose I read a part of the text, process it - write it into an array, write the contents of the array (modified text) into another file.

And you need to know the length of the entire source text.

Tell me, please, because I am confused with various FileInput-OutputStream, FileRider / Writer, StringBuffer / Builder.

Yes, I also have KOI8-U (Ukrainian) encoding, I tried to output it through:

public static String loadFileAsString(File file, String encoding) throws IOException { InputStreamReader f= (encoding==null ? new FileReader(file):new InputStreamReader( new FileInputStream(file),encoding)); StringBuffer sb= new StringBuffer(); try { char[] buf= new char[1000]; int len; while ((,0,buf.length))>=0) { sb.append(buf,0,len); } return sb.toString(); }catch(FileNotFoundException ex) { System.out.println("FileNotFoundException: " + file + " exc: " + ex); } finally { try {f.close();} catch (Exception e) {}; } return null; } 

as stated in is nonsense, so there is no need to encrypt)).

So really need help!

    1 answer 1

    so you can read the contents of a file into a string:

     // где f - ваш input stream reader BufferedReader reader = new BufferedReader(f); StringBuilder result = new StringBuilder(); String buff = null; while (null != (buff = reader.readLine())) { result.append(buff); } 

    read the contents of the array of charms:

     char [] characters = new char[result.length()]; result.getChars(0, result.length(), characters, 0);