Here you can find the source of readFile(String file)
Parameter | Description |
---|---|
file | a parameter |
public static String readFile(String file)
//package com.java2s; //License from project: Open Source License import java.io.FileInputStream; import java.io.IOException; public class Main { /**//from w w w . j a v a2 s . c o m * Really too bad assertThat(file).hasContent(String) didn't work with intellij idea to show me specific diffs. * This function is a quickie to get me string contents of a file so I can use String.isEqualTo(String), which * works very well with intellij idea's diff viewer. * * @param file * @return */ public static String readFile(String file) { try { FileInputStream fis = new FileInputStream(file); StringBuffer fileContent = new StringBuffer(""); byte[] buffer = new byte[1024]; int n; while ((n = fis.read(buffer)) != -1) { fileContent.append(new String(buffer, 0, n)); } return fileContent.toString(); } catch (IOException e) { throw new RuntimeException(e); } } }