1. read
public static void readfile(String filepath) { BufferedReader br = null; try { String sCurrentLine; br = new BufferedReader(new FileReader(filepath)); while ((sCurrentLine = br.readLine()) != null) { System.out.println(sCurrentLine); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (br != null) br.close(); } catch (IOException ex) { ex.printStackTrace(); } } }
2. write
public static void writefile(String filepath) { try { String content = "This is the content to write into file asndfsa"; File file = new File(filepath); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.close(); System.out.println("Done"); } catch (IOException e) { e.printStackTrace(); } }