/**
*
* DOC 将F盘下的test.jpg文件,读取后,再存到E盘下面.
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
FileInputStream in = new FileInputStream(new File("D:\\Buttom.gif"));// 指定要读取的图片
FileOutputStream out = new FileOutputStream(new File("E:\\Buttom.gif"));// 指定要写入的图片 路径 以及 后缀名
int n = 0;// 每次读取的字节长度
byte[] bb = new byte[1024];// 存储每次读取的内容
while ((n = in.read(bb)) != -1) {
out.write(bb, 0, n);// 将读取的内容,写入到输出流当中
}
out.close();// 关闭输入输出流
in.close();
}

/**

  • * DOC 从文件里读取数据.
  • *
  • * @throws FileNotFoundException
  • * @throws IOException
  • */
  • private static void readFromFile() throws FileNotFoundException, IOException {
  • File file = new File("E:\\helloworld.txt");// 指定要读取的文件
  • FileReader reader = new FileReader(file);// 获取该文件的输入流
  • char[] bb = new char[1024];// 用来保存每次读取到的字符
  • String str = "";// 用来将每次读取到的字符拼接,当然使用StringBuffer类更好
  • int n;// 每次读取到的字符长度
  • while ((n = reader.read(bb)) != -1) {
  • str += new String(bb, 0, n);
  • }
  • reader.close();// 关闭输入流,释放连接
  • System.out.println(str);
  • }

/**

  • * DOC 往文件里写入数据.
  • *
  • * @throws IOException
  • */
  • private static void writeToFile() throws IOException {
  • String writerContent = "hello world,你好世界";// 要写入的文本
  • File file = new File("E:\\helloworld.txt");// 要写入的文本文件
  • if (!file.exists()) {// 如果文件不存在,则创建该文件
  • file.createNewFile();
  • }
  • FileWriter writer = new FileWriter(file);// 获取该文件的输出流
  •      writer.write(writerContent);// 写内容
  • writer.flush();// 清空缓冲区,立即将输出流里的内容写到文件里
  • writer.close();// 关闭输出流,施放资源
  • }

最新文章

  1. 阿里云VPS服务器,ROS内网穿透
  2. Nginx反向代理+keepalived
  3. mac 下修改jenkins的 端口号
  4. go语言环境搭建
  5. 基于XMPP的IOS聊天客户端程序
  6. Python基本时间转换
  7. Swift - 使用NSNotificationCenter发送通知,接收通知
  8. Zend Framework 框架搭建
  9. Qt核心剖析:信息隐藏(三篇)
  10. C#中IDisposable
  11. 下篇: php 微商城 基于Thinkphp3.2框架开发
  12. Python 迭代器之列表解析
  13. 《android入门第一季》之android目录结构详解
  14. mybatis延迟加载详解
  15. python基础之文件操作和函数
  16. Typora中的Markdown教程
  17. 51nod--1265 四点共面 (计算几何基础, 点积, 叉积)
  18. Linux系列教程(三)——Linux学习技巧
  19. Linux基础命令---ifdown、ifup
  20. SpringBoot入门示例

热门文章

  1. java类的主动使用/被动使用
  2. 第二章 进程同步(二)——> 重点
  3. DRF之访问权限控制和访问频率控制(节流)
  4. mysql performance storage engine
  5. introJs用法及在webkit内核浏览器的一个报错
  6. linux IP 注释
  7. NOIP初赛篇——02计算机系统的基本结构
  8. Linux find 命令的初步实现(C++)
  9. Openstack neutron 网络服务 (七)
  10. 怎么判断是旧版本的ext3还是新版本?