Here you can find the source of fileToString(File file)
public static String fileToString(File file)
//package com.java2s; //License from project: Open Source License import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; public class Main { public static String fileToString(File file) { StringBuilder sb = new StringBuilder(); try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file))) { for (int b; (b = inputStream.read()) != -1;) { String s = Integer.toHexString(b).toUpperCase(); if (s.length() == 1) { sb.append('0'); }/*from w w w.ja v a2s .c o m*/ sb.append(s).append(' '); } return sb.toString().replace(" ", ""); } catch (IOException e) { Logger logger = Logger.getAnonymousLogger(); logger.log(Level.SEVERE, "Error while reading file.", e); return null; } } }