zoukankan      html  css  js  c++  java
  • java.io.*

    View Code

    创建文件test2.txt

    public class test {
        public static void main(String[] args) {
            File f = new File("D:\txt\test2.txt");
            if(!f.exists()){
                //可以创建
                try {
                    f.createNewFile();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            
            System.out.println("文件的位置" + f.getAbsolutePath());
            System.out.println("文件的大小" + f.length());
        }
    }
    View Code

    创建文件夹hello

    import java.io.*;
    
    public class test {
        public static void main(String[] args) {
            File f = new File("D:\txt\hello");
            if (!f.isDirectory()) {
                f.mkdir();
            }
        }
    }
    View Code
    文件字节流实现:文件——>内存  FileInputStream
    View Code

    FileOutputStream   写入文件中

    package io;
    
    /**
     * file类的基本用法
     */
    import java.io.*;
    
    public class test {
        public static void main(String[] args) {
            File f = new File("D:\txt\test1.txt");// 代表文件对象
            FileOutputStream fos = null;
            try {
                fos = new FileOutputStream(f);
                String s = "庞静赢是王志的娘子
    ";
                String s1 = "王志是庞静赢的相公";
                fos.write(s.getBytes());
                fos.write(s1.getBytes());
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    View Code
  • 相关阅读:
    JProfiler_SN_8_x key
    java格式化百分比
    获取每月第一天最后一天 java
    java 获取昨天日期
    eclipse git提交代码
    SIT与UAT的分别
    Spring <context:annotation-config/> 说明
    Hibernate日期映射类型
    Oracle查询备注信息
    Log4J入门
  • 原文地址:https://www.cnblogs.com/helloworld2019/p/10831492.html
Copyright © 2011-2022 走看看