How to read UTF8 encoded file using RandomAccessFile?

前端 未结 8 2119
深忆病人
深忆病人 2020-12-06 05:35

I have text file that was encoded with UTF8 (for language specific characters). I need to use RandomAccessFile to seek specific position and read from.

I want rea

8条回答
  •  一整个雨季
    2020-12-06 06:09

    Reading the file via readLine() worked for me:

    RandomAccessFile raf = new RandomAccessFile( ... );
    String line;
    while ((line = raf.readLine()) != null) { 
        String utf = new String(line.getBytes("ISO-8859-1"));
        ...
    }
    
    // my file content has been created with:
    raf.write(myStringContent.getBytes());
    

提交回复
热议问题