【Day28】输入输出流二

蓝桥杯Day1冲刺:从A+B问题掌握竞赛编程基本功与避坑指南 在算法竞赛和编程能力提升中,扎实的基本功是构建一切复杂解决方案的基石。其核心原理在于通过标准化的输入输出处理、严谨的边界条件判断以及对时间与空间复杂度的初步分析,形成稳定可靠的代码框架。掌握这些基础能力的技术价值在于,它能有效避免在简单题目上因非技术性失误而丢分,从而将宝贵的精力集中于攻克算法难点。无论是应对多组数据测试、精确解析输入格式,还是严格匹配输出要求,这些场景都是竞赛编程和日常工程实践中频繁遇到的通用问题。本文以蓝桥杯等算法竞赛中常见的**A+B问题变体**和**日期计算模拟**为例,深入剖析如何 阅读详情

目录

一、测试FileInputStream和FileOutStream的使用

二、测试FileReader和FileWriter的使用

三、FileInputStream用法

四、FileOutputStream用法

五、Reader类


一、测试FileInputStream和FileOutStream的使用

public class FileInputOutputStreamTest {

    @Test
    public void test(){
        File file = new File("hello.txt");
        FileInputStream fileInputStream=null;
        try {

            fileInputStream=new FileInputStream(file);

            byte[] bytes=new byte[5];
            int len;
            while ((len=fileInputStream.read(bytes))!=-1){
                String st=new String(bytes,0,len);
                //println加上ln每读完len长度的文件自动换行
                System.out.println(st);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch (IOException e) {

                }
            }
        }
    }

    /*

    复制图片
     */
    @Test
    public void test1(){
        File file = new File("干饭.jpg");
        File file1 = new File("干饭人.jpg");

        FileInputStream fileInputStream =null;
        FileOutputStream fileOutputStream =null;

        try {
            fileInputStream = new FileInputStream(file);
            fileOutputStream = new FileOutputStream(file1);

            byte[] chars=new byte[5];
            int num;
            while ((num = fileInputStream.read(chars)) != -1){
//            String str=new String(byte,0,num);
                //赋值操作
            fileOutputStream.write(chars,0,num);
            }
            System.out.println("赋值完成");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fileInputStream != null) {
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    //造一个快捷赋值方法,只需要通过改变参数值就行
    public void sanqu(String fist,String serack){
        File file = new File(fist);
        File file1 = new File(serack);

        FileInputStream fileInputStream =null;
        FileOutputStream fileOutputStream =null;

        try {
            fileInputStream = new FileInputStream(file);
            fileOutputStream = new FileOutputStream(file1);

            //数组长度大小影响传输速度
//            byte[] chars=new byte[5];//3127
            byte[] chars=new byte[1024];//23
            int num;
            while ((num = fileInputStream.read(chars)) != -1){
//            String str=new String(byte,0,num);
                //赋值操作
                fileOutputStream.write(chars,0,num);
            }
            System.out.println("赋值完成");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fileInputStream != null) {
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    @Test
    public void test2(){
    long start=System.currentTimeMillis();

    String fist="D:\\WenJian\\QQ\\添朵\\Image.png";
    String send="花花4.png";
    sanqu(fist,send);

    long end=System.currentTimeMillis();

        System.out.println("操作时间为:"+(end-start));
    }

}

二、测试FileReader和FileWriter的使用

public class FileReaderWriterTest1 {

    @Test
    public void test(){
        File file = new File("hello.txt");//相较于工程下
        System.out.println(file.getAbsolutePath());

        File file1 = new File("D:\\WenJian\\IDEA\\Java高级基础部分\\Day08输入输出流\\hello.txt");
        System.out.println(file1.getAbsolutePath());


    }

    /*
    将D:\WenJian\IDEA\Java高级基础部分\Day08输入输出流\hello.txt下的hello.txt文件内容读入内存,
    并输入控制台
     */
    @Test
    public void test1() throws IOException {
        //1、实例化File类的对象,指明操作文件
        File file = new File("hello.txt");

        //2、提供具体操作
        FileReader fileReader = new FileReader(file);

        //3、数据的读入
        //read():返回一个字符,如果返回-1,说明已经读完
        int read ;
        while ((read=fileReader.read())!=-1){
            System.out.print((char) read);
        }
        //4、流的关闭操作
        fileReader.close();
    }


    //对read()操作升级,使用read的重载方法
    @Test
    public void test2(){
        //1、File类的实例化
        File file = new File("hello.txt");
        //2、FileReader流的实例化
        FileReader fr=null;
        try {
            fr=new FileReader(file);


            //3、读入的操作
            char[] chars=new char[10];
            int ax;
            while((ax=fr.read(chars))!=-1){
                //注意,i<ax,而不是i<chars.length
                for (int i = 0; i < ax; i++) {
                    System.out.print(chars[i]);
                }
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (fr!=null){
                try {
                    fr.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


        //4、关闭流
    }

    /*
    从内存中写出数据到硬盘文件里
    输出的操作,file可以不存在
     */
    @Test
    public void test3(){
        //1、提供file类的对象,指明写出到的文件
        File file = new File("hello1.txt");
        //2、提供FileWriter的对象,用于数据的写出
        FileWriter fw=null;
        try {
            fw=new FileWriter(file);
            //加true可以不覆盖原来的文件
            //fw=new FileWriter(file,true);

            //3、写出操作
            fw.write("How do you do.\n");
            fw.write("I have a dream");
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //关闭流
            if(fw!=null){
                try {
                    fw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /*
    字符流不能用于处理字节文件
     */
    @Test
    public void test4(){
        //1、创建File类的对象,指明读入和写入的文件
        File file = new File("hello.txt");
        File file1 = new File("hello1.txt");
        //2、创建输入流和输出流的对象
        FileReader fr=null;
        FileWriter fw=null;
        try {
            fr=new FileReader(file);
            fw=new FileWriter(file1);

            //3、数据写入和读出操作
            char[] chars=new char[5];
            int ax;
            //把fr里的文件先读入数组中,赋值给fw
            while ((ax=fr.read(chars))!=-1){
                fw.write(chars,0,ax);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fr.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


        //4、关闭流
    }

    @Test
    public void test5(){
        //1、创建File类的对象,指明读入和写入的文件
        File file = new File("aifen1.jpg");
        System.out.println(file.getAbsolutePath());

        File file1 = new File("aifen2.jpg");
        //2、创建输入流和输出流的对象
        FileReader fr=null;

        FileWriter fw=null;
        try {
            fr=new FileReader(file);
            fw=new FileWriter(file1);

            //3、数据写入和读出操作
            char[] chars=new char[5];
            int ax;
            //把fr里的文件先读入数组中,赋值给fw
            while ((ax=fr.read(chars))!=-1){
                fw.write(chars,0,ax);

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fr.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
}
    //4、关闭流
    }
}

三、FileInputStream用法

/**
 * FileInputStream:读取txt内容
 * FileInputStream 从文件系统中的某个文件中获得输入字节。哪些文件可用取决于主机环境。
 *
 */
public class FileInputStreamTest {
//    public static void main(String[] args) throws Exception {
    //方式一
        @Test
        public void test1() throws IOException {
            //1、通过File类对象
            File file = new File("D:/a.txt");
            //2、创建FileInputStream类的对象
            FileInputStream ifs = new FileInputStream(file);
            //3、读取数据
//        int num = ifs.read();
//        System.out.println((char)num);
            //3、循环读取数据
            int num;
            while ((num = ifs.read()) != -1) {
                //循环判断的时候就已经开始自加一了
//            int numbe=ifs.read();
//            System.out.println(numbe);
                System.out.print((char) num);
            }
        }
        //方式二:
        @Test
    public void test2() throws IOException {
            //创建对象
            FileInputStream fileInputStream=new FileInputStream("D:/a.txt");

            //声明数组,长度为1024
            byte[] bytes =new byte[1024];
            //把读取的数据保存才数组中,然后把长度赋值给num
            int num=fileInputStream.read(bytes);
            //输出保存数据的长度
            System.out.println(num);//8
            //遍历数组
//            for (int i = 0; i < bytes.length; i++) {
//                System.out.print((char) bytes[i]);//asdfghjk  ………………长度为1024,值取完后剩下的都是空格
//            }

            for (int i = 0; i < num; i++) {
                System.out.print((char) bytes[i]);//asdfghjk
            }
            //关闭流:close
            fileInputStream.close();
        }
}

四、FileOutputStream用法

/**
 * FileOutputStream:向文件写入数据
 * FileOutputStream(文件地址,false(默认)/true)
 * false:会覆盖原文中所有内容     true:不会覆盖原文中所有内容
 *
 */
public class OutputStreamTest {

    @Test
    public void test1() throws Exception {

        //如果不写true,默认false,会覆盖原文中所有的文字
        FileOutputStream fo=new FileOutputStream("D:/a.txt",true);

        fo.write(65);
        System.out.println("数据写入完成");

        //判断是否运行
        if (fo != null) {
            fo.close();
        }
    }

    @Test
    public void test2(){
        FileOutputStream fileOutputStream=null;
        try {
            fileOutputStream=new FileOutputStream("D:/a.txt",true);
            String str="asdfghjsdfghjk";
            //字符串转换为bytes数组
            byte[] bytes=str.getBytes();
            fileOutputStream.write(bytes);
            System.out.println("书写成功");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if(fileOutputStream!=null) {
                    fileOutputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /*
    把数据从一个文本文件中读取,然后输入另一个文件中
    FileInputStream and FileOutputStream结合使用
     */
    @Test
    public void test3(){
        FileInputStream fileInputStream=null;
        FileOutputStream fileOutputStream=null;
        try {
            fileInputStream=new FileInputStream("D:/a.txt");
            fileOutputStream=new FileOutputStream("D:/b.txt",true);
            //定义一个外不变量,通过while循环可以不断的加一,获取数据,然后赋值
            int num;
            while ((num=fileInputStream.read())!=-1){
                //char有没有不影响结果
//                fileOutputStream.write((char)num);
                fileOutputStream.write(num);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fileInputStream.close();
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}

五、Reader类

/**
 *Reader类:
 *  InputStreamReader:
 *
 *  FileReader:
 *      file.encoding:查看编码格式
 *
 */
public class InputStremReaderTest {

    /*
    FileReader(File file)
     */
    @Test
    public void test() {

        InputStreamReader inputStreamReader = null;
        FileInputStream fileInputStream =null;

        try {
            fileInputStream = new FileInputStream("D:/a.txt");
            //按照默认的编码格式来读取
            inputStreamReader=new InputStreamReader(fileInputStream);
            //按照指定的编码格式来读取数据
//            inputStreamReader=new InputStreamReader(fileInputStream,"UTF-8");
            //读取数据
//            int read = inputStreamReader.read();
//            System.out.println(read);

            //方式一
//            int num;
//            while ((num=inputStreamReader.read())!=-1){
//                System.out.print((char) num);
//            }

            //方式二
            char[] chars=new char[1024];
            int num1=inputStreamReader.read(chars);
            System.out.println(num1);
            for (int i = 0; i  < num1; i++) {
                System.out.print(chars[i]);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if(inputStreamReader!=null) {
                    inputStreamReader.close();
                    fileInputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /*
    FileReader(String name)
    FileReader类对象只能按照本地平台的编码格式读取文件,如果文件和本地的编码格式不一致
    可能会出现乱码
     */
    @Test
    public void test1() {
        FileReader fileReader=null;
        try {
            fileReader=new FileReader("D:/a.txt");
            char[] chars=new char[1024];
            //读取数据
            int num=fileReader.read(chars);
            for (int i = 0; i < num; i++) {
                System.out.print(chars[i]);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

GPU运维面试题 【代码】GPU运维面试题。 阅读详情

相关推荐

戴尔G3/AWCC用户必看:揪出WMI Provider Host疯狂占用的元凶,附5.4.35旧版回退保姆级教程

本文针对戴尔G3/AWCC用户遇到的WMI Provider Host异常占用问题,提供了详细的诊断方法和解决方案。通过分析AWCC 5.5.14.0版本的资源占用问题,指导用户回退到稳定版AWCC 5.4.35,并附上保姆级教程和预防措施,帮助用户彻底解决系统卡顿问题。

weixin_30892037的博客 562

Java网络编程基础知识学习笔记

B站视频指路:尚硅谷Java入门视频教程(在线答疑+Java面试真题)_哔哩哔哩_bilibili 写在前面:马上秋招,打算从0开始再学一遍Java,开个知识点记录贴,就当做课堂笔记吧. 网络编程概述: ·Java是Internet上的语言 它从语言级上提供了对网络应用程序的支持 程序员很容易开发常见的网络应用程序 ·Java提供的网络类库,可以实现无痛的网络连接,联网的底层细节被隐藏在Java的本机安装系统里,由JVM进行控制.并且Java实现了一个跨平台的网络库,程序...

TIANJIAWEN的博客 1840

MCP4728 电路及stm32F103程序移植

写在前面 通过优快云查到一些MCP4728 的程序,结合程序及datasheet对于驱动的描述,理清了思路 感谢开路者! MCP4728的电路比较简单,见下文描述 应用电路 datasheet: 实际测试电路: SCL接stm32的PB10,SDA接PB11 RDY/BSY引脚和LDCA引脚,悬空 解释见截图: MCP4728地址 选择任意输出通道写入DAC输入寄存器 应用程序 int mcp4728_write_all_channel(float vol1, float vol2, fl

u013074298的专栏 5428

Java-IO(字节流)

1. 字节输出流 步骤: 1.创建字节输出流对象 2.调用 write() 方法写入数据 3.释放资源 写入数据的三种方式 public void write(int b) public void write(byte[] b) public void write(byte[] b,int off,int len) 代码如下: public class FileOutputStr...

weixin_48370579的博客 208

Verilog简易电梯控制系统(2层)

电梯处于1楼,按KEY3,LED3亮,电梯处于上行状态时,立刻按 KEY2,LED2亮,电梯继续运行至2楼,LED3灭;按KEY3,LED3亮,电梯处于上行状态时,立刻按 KEY0,LED0亮,电梯继续运行至2楼,LED3灭;电梯处于2楼,按KEY2,LED2亮,电梯处于下行状态时,立刻按 KEY3,LED3亮,电梯继续运行至1楼,LED2灭;电梯处于2楼,按KEY2,LED2亮,电梯处于下行状态时,立刻按 KEY1,LED1亮,电梯继续运行至1楼,LED2灭;电梯运行至2楼后LED1灭,2楼待机。

m0_54240221的博客 6957

深度学习驱动材料科学:晶体生成与性质预测技术综述

深度学习作为人工智能的核心技术,通过模拟人脑神经网络处理复杂数据,在多个领域展现出强大的模式识别与生成能力。其原理在于构建多层非线性变换,从海量数据中自动学习特征表示与映射关系。这一技术价值在于能够高效处理高维、非结构化数据,解决传统方法计算成本高、探索空间有限的问题。在工程实践中,深度学习已广泛应用于计算机视觉、自然语言处理等领域,并正深刻变革材料科学的研究范式。具体到材料领域,它通过学习已知材料的构效关系,实现对新材料性能的快速预测与逆向设计。应用场景包括但不限于新能源材料、半导体、催化剂等领域的高通量

weixin_28695161的博客 416

IO概述

什么是IO: java中I/O的操作主要是靠java.io包下面的类和接口来实现的,进入输入、输出操作。输入也可以叫做读取数据,输入也也可以叫做写入数据。 IO分类 根据数据的流向分为: 输入流和输出流 输入流: 把数据从其他设备上读取到内存当中的流 输出流:把数据从内存当中写入到其他设备上的流 根据数据的类型分为:字节流和字符流 字节流:以字节为单位,读写数据的流 字符流:以字符为单位,读写数据的流 IO流的顶级父类 输入流 输出流 字节流 字节输入流InputStream 字.

czw的博客 451

OpenCode:终端开源AI编程助手,多模型接入与实战指南

AI编程助手正在从IDE侧边栏走向终端环境。其核心原理是让模型直接读取项目文件、执行命令、查看报错,形成从诊断到修复的完整闭环,从而解决传统插件上下文割裂的问题。技术价值在于开源透明、模型无关,既可接入OpenAI等云端服务,也能通过Ollama连接本地模型,兼顾数据安全与离线场景。在工程实践中,它适用于长时间驻留项目、自动修Bug、团队统一AI工具链等需求。OpenCode正是这样一款终端AI助手,支持灵活配置第三方API密钥,提供免费档与Go套餐,并通过Skills技能系统让模型遵循标准操作流程。同时,

weixin_28745821的博客 328

FileInputStream中read()及read(byte b[])的用法

编码 1、ANSI编码:American National Standards Institute,即美国国家标准协会。当记事本或者软件采用Windows代码页中对应的"ANSI"编码时,在不同地区"ANSI"编码是不同的,在中国,"ANSI"就是GBK编码 2、ASCII编码:American Standard Code for Information Interchange,即美国信息交换...

u010389391的博客 1万+

基于大模型的急性重症胰腺炎全流程预测与诊疗方案研究

本研究构建了基于大模型的急性重症胰腺炎(SAP)全流程预测与诊疗系统,实现了从术前风险评估到术后康复管理的精准诊疗闭环。通过整合临床信息、实验室检查和影像学等多源数据,模型在测试集上预测准确率达X%,AUC为X,显著优于传统评分系统。研究创新性地将预测结果应用于手术方案制定、麻醉决策、并发症防控及个性化护理,形成智能化诊疗方案。验证结果显示模型具有良好的稳定性和临床适用性,同时配套的健康教育体系提升了患者自我管理能力。尽管存在样本局限性和模型可解释性等不足,该研究为SAP的精准诊疗提供了新范式,未来可通过扩

嵌入式毕设/课设资料清单(速查手册·文档模板·题库,持续更新)→ 见最新文章 1116

YOLO26中的PPM空间金字塔池化:改良设计与多尺度特征提取教程

在计算机视觉的语义分割任务中,准确理解图像中的上下文信息至关重要。例如,在街景图像中,可能同时存在远处的小汽车和近处的大建筑物,网络需要具备捕获多尺度上下文信息的能力。例如,要正确识别图像中的"船",不仅需要看到船本身的特征,还需要理解周围的水面环境。金字塔的每一层对应不同的池化尺度,从细粒度到粗粒度,形成了多层次的特征表示。PPM(Pyramid Pooling Module)正是为了解决这一问题而提出的模块,它通过构建金字塔形状的池化结构,有效地聚合不同尺度的上下文信息,从而提升语义分割的精度。

LXY_LOVE36的博客 82

输入inputStream字符流 Reader,Wirter

输入inputStream import java.io.FileInputStream; import java.io.IOException; ​ /* int read()从输入流中读取数据的下一个字节 int read(byte[] b)从输入流中读取一定数量的字节,并将其储存在缓冲区数组b中 void close()关闭输入流并且释放资源 1.创建对象 2.使用对象中的read方法 3释放资源 */ public class FileInputStream...

weixin_59519801的博客 589

Java全栈开发:充电桩管理系统项目实战

技术收获深入理解分布式系统架构掌握高并发场景解决方案提升系统设计能力经验教训前期需求分析的重要性技术选型需要考虑长期维护测试覆盖率的重要性未来展望引入AI预测故障支持更多支付方式优化用户体验通过此项目的开发,不仅实现了充电桩的智能化管理,也积累了宝贵的全栈开发经验。项目中的很多技术方案和架构设计都具有普遍适用性,可以在其他类似项目中借鉴使用。@Componentstatic {// 初始化状态转换规则。

exlink2012的专栏 1253

Day28

图片拷到字节数组中 图片(文件)不能直接转到字节数组中,需要一个程序做个中转。 图片(文件)----文件字节输入流---->程序----字节数组输出流---->字节数组 反过来就是:字节数组----字节数组输入流---->程序----文件字节输出流----图片(文件) 都是以程序为中心 图片读取到字节数组、字节数组写出到文件 package com.sxt.io; import java.io.*; /** * 1、图片读取到字节数组 * 2、字节数组写出到文件 */ publ

qq_50065571的博客 105

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

(十)重载输入输出流运算符(友元函数)

输出流重载函数引入友元函数

曾几何时的博客 2356

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

3.28作业

package com.qiku.day20; import java.io.*; public class Zy1 { //分别使用字符输入输出流FileWriter/FileReader // 文件输入输出流FileInputStream/FileOutputStream // 文件缓冲流BufferedInputStream/BufferedOutputStream // 字符缓冲流BufferedWriter/BufferedReader // 4种方式.

xiaolixiaozhou的博客 439

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Java高级编程–泛型、输入输出流–day06

知识点和问题整理1.泛型的作用是什么?2.泛型的使用3.如何自定义泛型结构:泛型类、泛型接口、泛型方法4.泛型类泛型方法使用注意事项5.泛型在继承方面的体现6.通配符的使用7.有限制的通配符8.样例代码,返回map中存放的所有T对象9.File 类的使用10.File 类的使用:常用构造器11.File 类的使用:路径分隔符12.File类的基本方法13.JavaIO原理14.流的分类15.IO体系16.将day09下的hello.txt文件内容读入程序中,并输出到控制台17.从内存中写出数据到硬盘的文件里

a1773570500的博客 1231

c++基础学习笔记——04-c++day09

在学习c++基础总结了笔记,并分享出来。有问题请及时联系博主:Alliswell_WP,转载请注明出处。 04-c++day09 目录:一、类型转换1、静态类型2、动态转换3、常量转换和重新解释转换二、C++异常1、异常的基本使用2、对自定义异常进行捕获3、栈解旋4、异常的接口声明5、异常变量生命周期6、异常的多态使用7、使用系统标准异常8、编写自己的异常类三、C++输入输出流1、标准输...

Alliswell_WP 406

【漫漫转码路】Day 28 C++ day01

C++环境搭建,Hello World输出,变量,常量,运算符,组合运算符,输入输出,条件语句

Mr_Oak的博客 263

黑马程序员-day20综合练习

---------------------- android培训、java培训、期待与您交流! ---------------------- import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; i

MirroMirro的专栏 481

java day14 IO流 & File

不用throws而用try-catch处理编译器异常的原因为 不能让程序停止执行 如果throws给jvm会停止程序运行并打印错误信息。注意 append 为true是追加文件数据 默认为false 替换当前文件的所有数据。字符串的构造方法中只能传两个数组 一个是字符数组返回值为 把字符都链接在一起的字符串。offest 为读取数组的起始位置 len为读取数组中元素的个数。此为文件复制的完整流程 如果指针为空不应该让其执行close语句。如果执行到try中报错语句则不继续执行try之后的语句。

moskidi的博客 889

day27-java

IO流、属性集properties、Commons_io框架

agjnhga的博客 127

手把手教你实现日期类

这篇文章介绍了如何用C++实现一个日期类

先做,然后做对,最后做得更好。学习就是为了自由呀,当你学会了怎么学习,想要学什么就学什么,需要什么就学什么,你就自由了。 993

day2_Android文件操作

1.文件输入输出流 1.1写文件到手机内存 public static boolean saveUserInfo(Context context, String number, String password) { try { // String path = "/data/data/com.itheima28.qqlogin/itheima28.txt"; // F

你若无殇,岁月无恙…… 370

C++——类和对象3|日期类型|Cout运算符重载|Cin运算符重载|const成员|

Date*类型。

weixin_49449676的博客 1411

java IO流 万字长文,建议收藏

一。流的概念和作用 流的本质是数据传输,根据数据传输特性将流抽象为各种类,方便更直观的进行数据操作。 IO流中使用了大量的装饰者模式 二。流的分类: 只要是处理纯文本数据,就优先考虑使用字符流。 除此之外都使用字节流。 三。字节流:InputStream和OutputStream字节流用来处理媒体数据 1、字节流和字符流的基本操作是相同的,但是要想操作媒体流就需要用到字节流。 2、字节流因为操作的是字节,所以可以用来操作媒体文件。(媒体文件也是以字节存储的) 3、读写字节流:In..

weixin_39755884的博客 138
上一篇: 【Day27】输入输出流一
下一篇: 【Day29】网络编程
「已注销」
博客等级 码龄4年 169粉丝 58原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

「已注销」

老板大气,I am happy

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值