/** * @param args */ public void readFile(String path){ try { InputStream in = new FileInputStream(path); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = ""; while((line=reader.readLine())!=null){ System.out.println(line); } reader.close(); in.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch(IOException e){ e.printStackTrace(); } }
public void writeFile(String fileName){ try { OutputStream out = new FileOutputStream(fileName); String src = "This is a new File"; byte[] bytes=src.getBytes(); out.write(bytes); out.flush(); out.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch(IOException e){ e.printStackTrace(); } }
public static void main(String[] args) { // TODO Auto-generated method stub FileOperator op = new FileOperator(); op.readFile("e:/ok.txt"); op.writeFile("e:/ok2.txt"); }