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();
}
}

Java file read & write的更多相关文章

  1. Java File类总结和FileUtils类

    Java File类总结和FileUtils类 文件存在和类型判断 创建出File类的对象并不代表该路径下有此文件或目录. 用public boolean exists()可以判断文件是否存在. Fi ...

  2. Java File 类的使用方法详解

    Java File类的功能非常强大,利用Java基本上可以对文件进行所有的操作.本文将对Java File文件操作类进行详细地分析,并将File类中的常用方法进行简单介绍,有需要的Java开发者可以看 ...

  3. Java File 类的使用方法详解(转)

    转自:http://www.codeceo.com/article/java-file-class.html Java File类的功能非常强大,利用Java基本上可以对文件进行所有的操作.本文将对J ...

  4. Java——File类成员方法

    body, table{font-family: 微软雅黑} table{border-collapse: collapse; border: solid gray; border-width: 2p ...

  5. An error occurred at line: 1 in the generated java file问题处理

    tomcat6启动后,加载jsp页面报错,提示无法将jsp编译为class文件,主要报错信息如下: An error occurred at line: 1 in the generated java ...

  6. 报错:An error occurred at line: 22 in the generated java file The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

    org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 22 in ...

  7. Java File类 mkdir 不能创建多层目录

    File f = new File("/home/jp/Upload"); if ((!f.exists()) || (!f.isDirectory())) {boolean re ...

  8. Java File类方法使用详解

    Java File类的功能非常强大,利用java基本上可以对文件进行所有操作.文本将对Java File 文件操作的类详细的分析,并将File类中的常用方法进行简单介绍. 构造函数 public cl ...

  9. 【转载】Java File操作汇总

    转载自博客:https://passport.cnblogs.com/user/signin?ReturnUrl=https%3A%2F%2Fwww.cnblogs.com%2F 本文通过大量的示例, ...

  10. JAVA File的创建及相对路径绝对路径

    http://blog.sina.com.cn/s/blog_9386f17b0100w2vv.html JAVA File的创建及相对路径绝对路径 (2011-12-09 08:27:56) 转载▼ ...

随机推荐

  1. Github-素材篇

    my github: http://github.com/yaochao

  2. 再看 AspriseOCR - OCR应用开发 -20151124

    再看 AspriseOCR - OCR应用开发 我写这个博文时间为 2015/11/24日,注意时间因为,网上很多文章时间上很久远,有的已经不能参考了 很多人面对从图片中识别文字或者数字0~9  A~ ...

  3. 搞定迅雷固件在TP-LINK WR720N,127.0.0.1 9000 获取不到激活码

    本帖最后由 exzzzipad 于 2014-7-2 22:33 编辑 基本情况:设备:TP-LINK WR720N目前固件:[antclan][20120825]720N-4M-NAS-withSA ...

  4. 关于Oracle出现listener refused the connection with the ORA-12505错误,解决方案

    出现listener refused the connection with the ORA-12505错误,解决方案: 1.首先重启一下电脑,释放被占用的1521端口 2.重启后打开Oracle D ...

  5. 来自 Thoughtram 的 Angular 2 系列资料

    Angular 2 已经正式 Release 了,Thoughtram 已经发布了一系列的文档,对 Angular 2 的各个方面进行深入的阐释和说明. 我计划逐渐将这个系列翻译出来,以便对大家学习 ...

  6. (转)Silverlight 与 JS交互

    转自 http://www.cnblogs.com/wt616/archive/2011/10/08/2201987.html 1.Silverlight直接调用JS的函数: 这个很简单,只要在HTM ...

  7. AX7: How to deploy a Package

    A. Using LCS services. B. Manual using command prompt. Here I’ll show using command prompt, as I fou ...

  8. JVM 垃圾回收器工作原理及使用实例介绍(转载自IBM),直接复制粘贴,需要原文戳链接

    原文 https://www.ibm.com/developerworks/cn/java/j-lo-JVMGarbageCollection/ 再插一个关于线程和进程上下文,待判断 http://b ...

  9. TCP/IP之大明内阁---协议的制定

    个人感言:真正的知识是深入浅出的,码农翻身" 公共号将苦涩难懂的计算机知识,用形象有趣的生活中实例呈现给我们,让我们更好地理解.感谢"码农翻身" 公共号,感谢你们的成果, ...

  10. 【WCF全析(二)】--服务配置部署详解

            上篇文章主要讨论了WCF的基本内容,其中包括WCF的术语.创建方法及WCF在开发过程中使用的意义,它不仅能够提供程序之间的通信,而且还能提供程序和数据间的通信,WCF提供了多样化的程序 ...