Skip to content

Instantly share code, notes, and snippets.

@team172011
Last active June 24, 2019 07:27
Show Gist options
  • Save team172011/656ade57a741a24ab5fd8cabf6db4166 to your computer and use it in GitHub Desktop.
Save team172011/656ade57a741a24ab5fd8cabf6db4166 to your computer and use it in GitHub Desktop.
Write the content of a file (InputStream) to an String variable
public static String getFileContent(FileInputStream fis, String encoding ) throws IOException{
try(BufferedReader br =new BufferedReader(new InputStreamReader(fis, encoding))){
StringBuilder sb = new StringBuilder();
String line;
while(( line = br.readLine()) != null ) {
sb.append( line );
sb.append( '\n' );
}
return sb.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment