Getting Junk characters while trying to print the file contents using Java
- by user1523797
I am reading a file's contents and trying to print the contents using java. But it prints junk characters along with the file content.
Code:
import java.io.*;
public class ReadFile {
public String readFile(String filePath){
StringBuilder contents = new StringBuilder();
File file = new File(filePath);
try{
…