How to delete file in Java

To delete a file in Java, we use the delete method of class. First construct a File object with the file you want to delete, and then call delete on the File object. If its deleted successfully, the method return true, otherwise return false, the cause of false deletion include the file does not exist or .

How to read UTF8 text file into String in Java

I was trying to read utf8 text from a text file ... . A file, in its nature its a byte array, even it is a text file. To get a String from the file, Java has ... , string is just a byte array. The function can just read the file raw data to memory and reference ... . code:java public static String readFileString ( String file ) { StringBuffer text = new

How to generate valid file name in Java

Sometimes, the file name string could be awkward especially when the file comes from the web. For example

If you try to save this file on the disk, Java throws an exception: