黑马JAVA P167 打印流、Properties/commins-io框架

 

 

 

 

 


 

 

package com.itheima.d6_printStream;

import java.io.PrintStream;

/**
 * 目标:了解改变输出语句的位置到文件
 */
public class PrintDemo2 {
    public static void main(String[] args) throws Exception {
        System.out.println("锦瑟无端五十弦");
        System.out.println("一弦一柱思华年");

        //改变输出语句的位置(重定向)
        PrintStream ps  = new PrintStream("D:\\code\\javasepromax\\io-app2\\src\\loo.txt");
        System.setOut(ps); //把系统打印流改成我们自己的打印流

        System.out.println("庄生晓梦迷蝴蝶");
        System.out.println("望帝春心托杜鹃");
    }
}

 


 

 

 

 

package com.itheima.d7_properties;

import java.io.FileWriter;
import java.util.Properties;

public class PropertiesDemo01 {
    public static void main(String[] args) throws Exception{
        //需求:使用Properties把键值对存入到属性文件中去。
        Properties properties = new Properties();
        properties.setProperty("admin","123456");
        properties.setProperty("dlei","003197");
        properties.setProperty("heima","itcast");
        System.out.println(properties);

        /**
         * 参数一:保存管道 字符输出流管道
         * 参数二:保存心得
         */

        properties.store(new FileWriter("D:\\code\\javasepromax\\io-app2\\src\\ps.properties")
                , "this is users!! i am very happy!");
    }
}

 

package com.itheima.d7_properties;

import java.io.FileReader;
import java.util.Properties;

public class PropertiesDemo02 {
    public static void main(String[] args) throws Exception {
        //需求: Properties 读取属性文件中的键值对信息。 (读取)
        Properties properties = new Properties();
        System.out.println(properties);

        //加载属性文件中的键值对数据到属性对象properties中去
        properties.load(new FileReader("D:\\code\\javasepromax\\io-app2\\src\\ps.properties"));

        System.out.println(properties);
        String rs = properties.getProperty("dlei");
        System.out.println(rs);
        String rs1 = properties.getProperty("admin");
        System.out.println(rs1);

    }
}

 


 

package com.itheima.d8_commons_io;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;

public class CommonsIODemo01 {
    public static void main(String[] args)throws Exception {

        //1.完成文件的复制!
//        IOUtils.copy(new FileInputStream("D:\\测试\\佘颖欣.jpg")
//        , new FileOutputStream("D:\\测试\\佘颖欣2.jpg"));

        //2.完成文件复制到某个文件夹下!
//        FileUtils.copyFileToDirectory(new File("D:\\测试\\佘颖欣.jpg") , new File("D:\\"));

        //3.完成文件夹复制到某个文件夹下!
//        FileUtils.copyDirectoryToDirectory(new File("D:\\测试") , new File("D:\\new"));
//        FileUtils.deleteDirectory(new File("D:\\new"));

        //JDK1.7 自己也做了一些一行代码完成复制的操作:New IO的技术(NIO技术)
//        Files.copy(Path.of("D:\\测试\\佘颖欣.jpg"), Path.of("D:\\测试\\佘颖欣2.jpg"));
//        Files.deleteIfExists(Path.of("D:\\new"));
        Files.copy(Path.of("D:\\测试\\佘颖欣.jpg"),Path.of("D:\\测试\\佘颖欣2.jpg"));

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值