博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java 基础知识
阅读量:4618 次
发布时间:2019-06-09

本文共 911 字,大约阅读时间需要 3 分钟。

  1. Path使用

    • 构造Path对象

      Path path1 = Paths.get("C:/", "Xmp");Path path2 = Paths.get("C:/Xmp");
    • File和Path之间的转换

      File file = new File("C:/my.ini");Path p1 = file.toPath();File file = p1.toFile();
    • 创建文件

      Path p = Paths.get("C:\\mystuff.txt");if (!Files.exists(p)) {    try {        Files.createFile(p);    } catch (IOException e) {        e.printStackTrace();    }}
    • 读取文件

      Path p = Paths.get("C:\\mystuff.txt");try {    BufferedReader reader = Files.newBufferedReader(p);    String line = null;    while ((line = reader.readLine()) != null) {        System.out.println(line);    }} catch (IOException e) {    e.printStackTrace();}
    • 写入文件

      Path p = Paths.get("C:\\mystuff.txt");try {    BufferedWriter writer = Files.newBufferedWriter(p);    writer.write("hello");    writer.write("world");    writer.flush();    writer.close();} catch (IOException e) {    e.printStackTrace();}

转载于:https://www.cnblogs.com/liuweiqc/p/10984589.html

你可能感兴趣的文章
关于 IOS 发布的点点滴滴记录(一)
查看>>
《EMCAScript6入门》读书笔记——14.Promise对象
查看>>
CSS——水平/垂直居中
查看>>
Eclipse连接mysql数据库jdbc下载(图文)
查看>>
Python中Selenium的使用方法
查看>>
三月23日测试Fiddler
查看>>
20171013_数据库新环境后期操作
查看>>
poj 1654 && poj 1675
查看>>
运维派 企业面试题1 监控MySQL主从同步是否异常
查看>>
Docker 版本
查看>>
poj 1753 Flip Game
查看>>
在深信服实习是怎样的体验(研发测试岗)
查看>>
Linux免密码登陆
查看>>
SpringMVC中文件的上传(上传到服务器)和下载问题(二)--------下载
查看>>
Socket & TCP &HTTP
查看>>
osip及eXosip的编译方法
查看>>
Hibernate composite key
查看>>
[CF Round #294 div2] D. A and B and Interesting Substrings 【Map】
查看>>
keepalived+nginx安装配置
查看>>
我的2015---找寻真实的自己
查看>>