• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
仅供参考
博客园    首页    新随笔    联系   管理    订阅  订阅
File

File file = new File();

file.createNewFile();

file.delete();

File[] files = file.listFiles();

String[] list = file.list();

boolean exists = file.exists();

String absolutePath = file.getAbsolutePath();

String name = file.getName();

String path = file.getPath();

boolean file2 = file.isDirectory()

boolean file1 = file.isFile();

long length = file.length();

boolean mkdir = file.mkdir();

boolean mkdirs = file.mkdir();

file.delete();

static String pathSeparator 与系统有关的路径分隔符,为了方便,它被表示为一个字符串。
static char pathSeparatorChar 与系统有关的路径分隔符。
static String separator 与系统有关的默认名称分隔符,为了方便,它被表示为一个字符串。
static char separatorChar 与系统有关的默认名称分隔符。

FileOutputStream fos = new FileOutputStream("day28_IO\a.txt");
// 2.调用FileOutputStream对象中的方法write,把数据写入到文件中
fos.write(97);
// 3.释放资源。
fos.close();

FileOutputStream fos = new FileOutputStream("day28_IO\c.txt", true);//原来的数据还会存在,末尾添加
//2.调用write()
fos.write("HelloWorld".getBytes());
//3.关闭流对象
fos.close();

Windows系统里,换行符号是\r\n。把以指定是否需要追加续写换行。

Linux系统里,换行符号是 /n

mac系统里,换行符号是/r

Unix系统里,每行结尾只有换行,即/n

回车符\r和换行符\n

  • 回车符:回到一行的开头
  • 换行符:下一行(newLine)。

public static void main(String[] args) throws IOException {
//1.创建对象
FileOutputStream fos = new FileOutputStream("day28_IO\c.txt", true);//原来的数据还会存在,末尾添加
// 实现数据换行
fos.write("\r\n".getBytes());
//2.调用write()
fos.write("Java31".getBytes());
//3.关闭流对象
fos.close();
}

posted on 2020-12-15 23:30  七0  阅读(189)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3