Quantcast
Channel: How do I create a Java string from the contents of a file? - Stack Overflow
Viewing all articles
Browse latest Browse all 36

Answer by user590444 for How do I create a Java string from the contents of a file?

$
0
0
import java.nio.file.Files;

.......

 String readFile(String filename) {            File f = new File(filename);            try {                byte[] bytes = Files.readAllBytes(f.toPath());                return new String(bytes,"UTF-8");            } catch (FileNotFoundException e) {                e.printStackTrace();            } catch (IOException e) {                e.printStackTrace();            }            return "";    }

Viewing all articles
Browse latest Browse all 36

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>