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
  • 相关阅读:
    iOS 关于NSNotificationCenter
    IOS UITableView reload 刷新某一个cell 或 section
    IOS AFNetWorking 设置超时时间
    IOS AFNetWorking
    IOS 十六进制字符串转换成UIColor
    IOS 长姿势---双击Home键
    IOS 关于 NSUserDefault
    方正璞华培训讲师
    localStorage使用总结
    Promise的简单用法
  • 原文地址:https://www.cnblogs.com/helloworld2019/p/10831492.html
Copyright © 2011-2022 走看看