栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

JAVA基础13

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JAVA基础13

package com.h;

import java.io.File;
import java.io.IOException;

public class Test_exceptionDemo {
    
    public static void main(String[] args) throws IOException {

//        File f3_1 = new File("d:\aa\bb");
//        File f3_2 = new File(f3_1,"bb.txt");
//
//        System.out.println("mkdirs"+"-------------"+f3_1.mkdirs());
//        System.out.println("createNewFile"+"-------------"+f3_2.createNewFile());

        File f3_2 = new File("aa");
        File f3_1 = new File("aa\a.txt");

        f3_1.isDirectory();
        f3_1.isFile();
        f3_1.exists();

        f3_1.getAbsoluteFile();
        f3_1.getPath();
        f3_1.getName();


//        System.out.println(f3_2.mkdirs());
//        System.out.println(f3_1.createNewFile());
        System.out.println(f3_2.delete());

    }
}

package com.h;


import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class Test_Io {
    
    public static void main(String[] args) throws IOException {
//        FileOutputStream fos = new FileOutputStream("aa.txt");
//
//        fos.write(65);
//        fos.write(66);
//        fos.close();

//        FileOutputStream fos = new FileOutputStream(new File("bb.txt"));
//        fos.write("ABCDEFG".getBytes(StandardCharsets.UTF_8));
//        fos.close();

//            FileOutputStream fos = null;
//
//        try {
//            fos = new FileOutputStream("aa.txt");
//            fos.write("hello".getBytes(StandardCharsets.UTF_8));
//        } catch (IOException e) {
//            e.printStackTrace();
//        } finally {
//            if(fos != null) {
//                try {
//                    fos.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }

//        FileInputStream fis = new FileInputStream("bb.txt");
//        int by;//read读到的byte码值是一个数字
//        while ((by=fis.read()) != -1){//每次读都判断是否结尾,结尾为-1
//            System.out.print((char)by);//强转为char类型读出字符
//        }
//        fis.close();

            FileInputStream fis = new FileInputStream("bb.txt");
            byte[] bys = new byte[1024];//标准的读只能读1024的整数倍数
            int len;
            while (-1 != (len = fis.read(bys))){
                System.out.println(new String(bys,0,len));//每次只转换对应长度的byte到字符串
            }
            fis.close();

    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/306876.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号