Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test{
- public static void main(String[] args) {
- try (BufferedReader reader = new BufferedReader(new FileReader("test.txt"))) {
- long[] unicodeArray = new long[65536];
- while (reader.ready()) {
- char[] charArray = reader.readLine().toCharArray();
- for (char c : charArray) {
- unicodeArray[(int) c]++;
- }
- }
- for (int i = 0; i < unicodeArray.length; i++) {
- if (unicodeArray[i] > 0) {
- System.out.println("Symbol: " + (char) i + " Freq: " + unicodeArray[i]);
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- try (InputStream reader = new FileInputStream("test.txt")) {
- long[] unicodeArray = new long[65536];
- byte[] buf = new byte[4096];
- int len;
- short maxChar;
- long maxCharCnt = 0;
- while ((len = reader.read(buf)) > 0) {
- for (int i = 0; i < len; i += 2) {
- short c = (buf[i] << 8) || (buf[i + 1] & 0xff);
- unicodeArray[c]++;
- if (unicodeArray[c] > maxCharCnt) {
- maxChar = c;
- maxCharCnt = unicodeArray[c];
- }
- }
- System.out.println((char)maxChar);
- }
Add Comment
Please, Sign In to add comment