I just started learning Java and I want to know how to open txt file and include text to it. So please provide me some suggestions about this. Any help will be appreciated.
I just started learning Java and I want to know how to open txt file and include text to it. So please provide me some suggestions about this. Any help will be appreciated.
Try the following code to solve your problem:
Code:try { FileOutputStream flout = new FileOutputStream(directory / file.txt); flout.write(text.getBytes()); flout.close(); } catch(IOException ioe) { / / Handle exceptions related to file access }
See the code given below which may help you:
Code:import java.io.File; Public class mfl { Public mfl() { great(); } Public String mthd(String path) throws Exception{ File fl = new File(path); if(fl.exists()& & File.canRead()){ return "Ok"; / / message } else { return "Not Ok"; / / message } } }
Bookmarks