I have a requirement in which I need to read java class file as a string in java.
my code is
String path = "C:/java/MainClass.class";
String content = new String(Files.readAllBytes(Paths.get(path)));
When ever I print content variable, I am expecting the code to work as it works for simple text file, my expected output is something like this
public class MainClass { public static void main(String[] args) { System.out.print("This is a test file"); } }
In future I also want to read files in other formats as a string for ex: .cs, .py, .config
Please Let me know what are the changes I need to take care so that I read it as a simple text file.