Java FileInputStream Read readFile(String file)

Here you can find the source of readFile(String file)

Description

Really too bad assertThat(file).hasContent(String) didn't work with intellij idea to show me specific diffs.

License

Open Source License

Parameter

Parameter Description
file a parameter

Declaration

public static String readFile(String file) 

Method Source Code

//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);
        }
    }
}

Related

  1. readFile(final String fileNamePath)
  2. readFile(InputStream ios)
  3. readFile(InputStream iStream)
  4. readFile(String destination)
  5. readFile(String file)
  6. readFile(String file)
  7. readFile(String file)
  8. readFile(String file)
  9. readFile(String file)