Java 日看一类(11)之IO包中的DataInputStream类

Java IO详解 IO即Input和Output,即输入和输出。这里的输入和输出都是相对于内存来说的。 阅读详情

该类没有引入外界包

继承了FilterInputStream

完成了上篇文章所讲到的DataInput接口




类头注释

/**
 * A data input stream lets an application read primitive Java data
 * types from an underlying input stream in a machine-independent
 * way. An application uses a data output stream to write data that
 * can later be read by a data input stream.
 * <p>
 * DataInputStream is not necessarily safe for multithreaded access.
 * Thread safety is optional and is the responsibility of users of
 * methods in this class.
 *
 * @author  Arthur van Hoff
 * @see     java.io.DataOutputStream
 * @since   JDK1.0
 */

大意如下:

该类是一个数据输入流,可以让应用从底层输入流中读取Java基础数据类型且该方法与机器无关

一个应用使用数据输出流写出的数据稍后可以由数据输入流读取

DataInputStream对于多线程访问是不保证安全的

线程安全可选,但由该类方法的使用者负责




该类含有的成员变量:

readUTF中Byte缓冲

private byte bytearr[] = new byte[80];

readUTF中Char缓冲

private char chararr[] = new char[80];

readlong专用缓冲

private byte readBuffer[] = new byte[8];




该类含有的方法:

构造方法,简单调用父类构造方法

public DataInputStream(InputStream in) {
    super(in);
}

从输入流中读取byte数据(尝试读满缓冲,返回实际读取长度)

public final int read(byte b[]) throws IOException {
    return in.read(b, 0, b.length);
}

从输入流中读取byte数据(尝试向缓冲区特定位置读取特定长度数据)

public final int read(byte b[], int off, int len) throws IOException {
    return in.read(b, off, len);
}

从输入流中读取byte数据(强制读满,未读满会抛出各种事件)

public final void readFully(byte b[]) throws IOException {
    readFully(b, 0, b.length);
}

从输入流中读取byte数据(强制向缓冲区特定位置读取特定长度数据)

public final void readFully(byte b[], int off, int len) throws IOException {
    if (len < 0)
        throw new IndexOutOfBoundsException();
    int n = 0;
    while (n < len) {//读取够量或者文件结束
        int count = in.read(b, off + n, len - n);
        if (count < 0)
            throw new EOFException();
        n += count;
    }
}

跳过输入流后续的n个字符,返回实际跳过的字符数

public final int skipBytes(int n) throws IOException {
    int total = 0;//跳过字符记录
    int cur = 0;//记录底层流每次实际跳过字符

    while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
        total += cur;
    }

    return total;
}

判定读取字符是否为0(一般编码中0对应空,如ascii)

public final boolean readBoolean() throws IOException {
    int ch = in.read();//读取下一个字节并返回int值(将二进制码转化为十进制)
    if (ch < 0)
        throw new EOFException();
    return (ch != 0);
}

读取一个byte数据,返回有符号8位值(二进制码,首位符号位)

public final byte readByte() throws IOException {
    int ch = in.read();
    if (ch < 0)
        throw new EOFException();
    return (byte)(ch);
}

读取一个byte数据,返回无符号8位值(int型)

public final int readUnsignedByte() throws IOException {
    int ch = in.read();
    if (ch < 0)
        throw new EOFException();
    return ch;
}

读取两个byte字节通过移位和强制类型转换返回short

public final short readShort() throws IOException {
    int ch1 = in.read();
    int ch2 = in.read();
    if ((ch1 | ch2) < 0)
        throw new EOFException();
    return (short)((ch1 << 8) + (ch2 << 0));
}

返回无符号16位(把符号为也化成数值位)

public final int readUnsignedShort() throws IOException {
    int ch1 = in.read();
    int ch2 = in.read();
    if ((ch1 | ch2) < 0)
        throw new EOFException();
    return (ch1 << 8) + (ch2 << 0);
}

读取两个字节返回char

public final char readChar() throws IOException {
    int ch1 = in.read();
    int ch2 = in.read();
    if ((ch1 | ch2) < 0)
        throw new EOFException();
    return (char)((ch1 << 8) + (ch2 << 0));
}

读取四个字节返回int值

public final int readInt() throws IOException {
    int ch1 = in.read();
    int ch2 = in.read();
    int ch3 = in.read();
    int ch4 = in.read();
    if ((ch1 | ch2 | ch3 | ch4) < 0)
        throw new EOFException();
    return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
}

读取8个字节返回long值

public final long readLong() throws IOException {
    readFully(readBuffer, 0, 8);
    return (((long)readBuffer[0] << 56) +//位数较大时需先转化为long型,否则无法准确储存移位后数据(java中整数默认为int)
            ((long)(readBuffer[1] & 255) << 48) +
            ((long)(readBuffer[2] & 255) << 40) +
            ((long)(readBuffer[3] & 255) << 32) +
            ((long)(readBuffer[4] & 255) << 24) +
            ((readBuffer[5] & 255) << 16) +
            ((readBuffer[6] & 255) <<  8) +
            ((readBuffer[7] & 255) <<  0));
}

读取四个字节返回float

public final float readFloat() throws IOException {
    return Float.intBitsToFloat(readInt());//先化为int
}

读取8个字节化为double

public final double readDouble() throws IOException {
    return Double.longBitsToDouble(readLong());//先化为long
}

读取单行文本返回字符串

    public final String readLine() throws IOException {
        char buf[] = lineBuffer;//读取缓冲区

        if (buf == null) {
            buf = lineBuffer = new char[128];//初始化缓冲区
        }

        int room = buf.length;//剩余可用空间
        int offset = 0;//读取指针
        int c;

loop:   while (true) {
            switch (c = in.read()) {
              case -1:
              case '\n'://新行符
                break loop;

              case '\r':
                int c2 = in.read();
                if ((c2 != '\n') && (c2 != -1)) {//c2不为换行符且c2读取成功
                    if (!(in instanceof PushbackInputStream)) {//进行类型检查,判断传入的该InputStream类是否是PushbackInputStream或者其子类
                        this.in = new PushbackInputStream(in);
                    }
                    ((PushbackInputStream)in).unread(c2);//将c2回退到缓冲区前面
                }
                break loop;

              default:
                if (--room < 0) {//room大小非正
                    buf = new char[offset + 128];//生成新缓冲区
                    room = buf.length - offset - 1;
                    System.arraycopy(lineBuffer, 0, buf, 0, offset);
                    lineBuffer = buf;
                }
                buf[offset++] = (char) c;
                break;
            }
        }
        if ((c == -1) && (offset == 0)) {
            return null;
        }
        return String.copyValueOf(buf, 0, offset);
    }

默认读本类字符(改版UTF-8),返回字符串

public final String readUTF() throws IOException {
    return readUTF(this);
}

读取特定DataInput的字符(改版UTF-8),返回字符串

public final static String readUTF(DataInput in) throws IOException {
    int utflen = in.readUnsignedShort();//utf长度
    byte[] bytearr = null;
    char[] chararr = null;
    if (in instanceof DataInputStream) {//检查传入类是否为本类
        DataInputStream dis = (DataInputStream)in;
        if (dis.bytearr.length < utflen){
            dis.bytearr = new byte[utflen*2];//初始化缓冲区
            dis.chararr = new char[utflen*2];
        }
        chararr = dis.chararr;//绑定
        bytearr = dis.bytearr;
    } else {
        bytearr = new byte[utflen];//直接初始化
        chararr = new char[utflen];
    }

    int c, char2, char3;
    int count = 0;//共读取长度
    int chararr_count=0;

    in.readFully(bytearr, 0, utflen);//填充byte缓冲

    while (count < utflen) {
        c = (int) bytearr[count] & 0xff;
        if (c > 127) break;
        count++;
        chararr[chararr_count++]=(char)c;
    }

    while (count < utflen) {
        c = (int) bytearr[count] & 0xff;
        switch (c >> 4) {
            case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
                /* 0xxxxxxx*/
                count++;
                chararr[chararr_count++]=(char)c;
                break;
            case 12: case 13:
                /* 110x xxxx   10xx xxxx*/
                count += 2;
                if (count > utflen)
                    throw new UTFDataFormatException(
                        "malformed input: partial character at end");
                char2 = (int) bytearr[count-1];
                if ((char2 & 0xC0) != 0x80)
                    throw new UTFDataFormatException(
                        "malformed input around byte " + count);
                chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
                                                (char2 & 0x3F));
                break;
            case 14:
                /* 1110 xxxx  10xx xxxx  10xx xxxx */
                count += 3;
                if (count > utflen)
                    throw new UTFDataFormatException(
                        "malformed input: partial character at end");
                char2 = (int) bytearr[count-2];
                char3 = (int) bytearr[count-1];
                if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
                    throw new UTFDataFormatException(
                        "malformed input around byte " + (count-1));
                chararr[chararr_count++]=(char)(((c     & 0x0F) << 12) |
                                                ((char2 & 0x3F) << 6)  |
                                                ((char3 & 0x3F) << 0));
                break;
            default:
                /* 10xx xxxx,  1111 xxxx */
                throw new UTFDataFormatException(
                    "malformed input around byte " + count);
        }
    }
    // The number of chars produced may be less than utflen
    return new String(chararr, 0, chararr_count);
}




DataInputStream类的设计思路应该是:想要设计一个有这些功能的类,但Java不支持多重继承,所以把该类做成了一个接口(DataInput),同时DataInputStream就是该类实例化的体现之一。该类的代码除了readUTF()稍微复杂一些,其他都是十分基础和简单的,只是对各数据类型的空间占用有所涉及。




DataInputStream 介绍_动力节点Java学院整理 DataInputStream 是数据输入流。它继承于FilterInputStream。 DataInputStream 是用来装饰其它输入流,它“允许应用程序以与机器无关方式从底层输入流中读取基本 Java 数据类型”。应用程序可以使用DataOutputStream(数据输出流)写入由DataInputStream(数据输入流)读取的数据。 立即下载

相关推荐

基于STM32的半导体制冷片温度控制

制冷片温度控制,温控范围15℃~45℃,本人菜鸡一枚,大佬绕路。 #include "stm32f10x_gpio.h" #include "relay.h" void relay_Init(void){ GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//Ê...

大白兔的博客 9017

Java 虚拟机性能分析工具

这两天看了下Java虚拟机性能分析相关的东西,做一下总结,主要是jconsole和jvisualvm这两个工具,在java的jdk/bin里面都内置了 jonsole

newbaby2012的专栏 607

cocos creator接入微信登陆sdk ios篇

cocos creator接入微信登陆sdk ios篇 背景已经在Android篇里面交代过了,有兴趣的朋友可以再看看Android篇 步骤 去微信开放平台下载ios平台所需要的sdk 在“info”标签栏的“URL type“添加“URL scheme”为你所注册的应用程序id 在“info”标签栏的“LSApplicationQueriesSchemes“添加weixin 将SDK文件中...

凤小鹿的博客 6363

java 输入格式错误,java - 使用DataInputStream时,Java中的字节周围输入格式错误 - 堆栈内存溢出...

我有一个代码,它接受输入流并打印它。 当我使用BufferedReader ,代码在控制台中打印流,但是当我使用DataInputStream我收到以下错误:Exception in thread "main" java.io.UTFDataFormatException: malformed input around byte 6351at java.io.DataInputStream.re...

weixin_29099729的博客 710

Origin作图——等高线图

最近做一个测试数据图,开始想通过用热图来展示,结果发现热图有很多的小方块,很难呈现出最好的效果,因为数据是有一层一层的递进效果,因此经过尝试后,发现等高线图是个好选择。 热图展示效果如下:其中有很多的小方块不适合,热图制图方法前面有记录。 下面展示等高线图制作方法。首先是导入数据,可以从excal导入,也可以直接复制进去。等方法。 选中要展示的数据,绘图----等高线图 选中箭头,确定。 双击图像,点击线,我们需要把线隐藏了. 双击图像,我们需要调色板,根据自己的选择,一般用调色板的颜色。

qq_42278015的博客 1万+

别再乱点U盘里的.exe了!手把手教你清除‘Usb Disk.exe’病毒并恢复隐藏文件

本文详细介绍了如何识别和清除U盘病毒(如Usb Disk.exe),并提供从终止病毒进程到恢复隐藏文件的完整步骤。通过禁用自动播放、清理注册表和使用命令行工具,帮助用户彻底清除病毒并预防未来感染,确保数据安全。

weixin_42530732的博客 596

eclipse启动报错:

eclipse启动错误

尘同学的博客 1504

【YOLOv13多模态融合改进】| CFT:跨模态融合Transformer | 利用Transformer的自注意力机制,解决跨模态融合中的长距离依赖和全局信息整合问题

本文记录的是利用 CFT 模块改进 YOLOv13 的多模态目标检测网络模型。的设计出发点在于解决传统多模态检测中跨模态特征融合不充分的问题,即当不同模态数据需协同检测时,基于CNN的方法因局部卷积的局限性,难以捕捉长距离依赖和全局模态间的互补信息,导致复杂光照、遮挡等场景下检测精度不足。本文利用模块,将多模态特征序列拼接后自动学习模态内与模态间的交互权重,在特征提取阶段整合全局上下文信息,增强对不同模态互补特征的利用能力,从而提升模型在多模态场景下的检测鲁棒性与准确性。Cross-Modality Fus

Limiiiing的博客 540

11_Java的IO流(面试)_DataInputStream和DataOutputStream的特点

11 DataInputStream和DataOutputStream的特点 1:二者都是处理流,要以一个节点流为参数; 二者被称为数据流,是用来操作基本数据类型的。 2、用DataInputStream 写入一个类型的数据,用 DataOutputStream读出数据时可以保持类型不变。 数据流特点: 写入是什么类型的数据,读出是相应类型的数据; 要先写后读;用 DataOutputStrea...

毅君帅 3287

【华为机试真题 Python实现】分苹果

《华为机试真题》专栏含牛客网华为专栏、华为面经试题、华为OD机试真题。如果您在准备华为的面试,期间有想了解的可以私信我,我会尽可能帮您解答,也可以给您一些建议!本文解法非最优解(即非性能最优)。A,B两个人把苹果分为两堆,A希望按照它的计算规则等分苹果,他的计算规则是按照二进制加法计算,并且不计算走位,12+5=9(1100+0101=9), B的计算规则是十进制加法,包括正常进位,B希望在满足A的情况下获取苹果重量最多,输入苹果的数量和每个苹果重量,输出满足A的情况下获取的苹果总重量, 如果无法满足A的要

3414

虚拟机VMware Horizon Client与主机之间建立共享文件夹

因经常需要在虚拟机和主机之间传递一些日常文件,所以建立共享文件夹。 虚拟机中安装的系统为win10,主机中的系统为win10。 步骤: 第一步:先在虚拟机win10中新建文件夹(我重命名为“共享文件夹”),然后右键属性->共享->共享 进去之后点击自己的账户名 然后点共享。操作完成后,再返回属性界面就能看到该文件夹已经共享而且出现了共享链接,记下此链接。 第二步:回到主机桌面->此电脑->最上面计算机->添加一个网络位置- 点击下一步 然后自定义网络位置,下一步,如下图

AnChenliang_1002的博客 1万+

java中的scanner是什么_JAVA中的Scanner类与IO流那些有什么区别

JAVA中的Scanner类与IO流那些有什么区别Scanner类主要是用来直接读取字符及字符串的比如in.readChar()、in,readChars()等方法,我们一般应用都是通过一个默认的System.in对象来得到Scanner对象的,如Scannerinput=newScanner(System.in),System.in本身是一个InputStream类型对象,代表了控制台的输入,其...

weixin_30301989的博客 883

FCC 首个扫地机器人豁免落地,Matic 凭什么抢先?

Matic获FCC首个扫地机器人豁免,实为提前布局的合规姿态。其产品在美国组装,并采用已认证射频模组,虽未达65%美国成分门槛,但已具备“本土制造”优势。豁免本质是对既有合规状态的确认,而非解救。此举在商业上放大品牌价值,抢占“安全、合规、本土”叙事高地,凸显供应链安全正取代技术标准成为监管核心。未来合规成本将攀升,规则主导权仍在FCC手中。

致力于lidar应用开发 101

java流类_Java IO 技术之基本流类

流式IO流(Stream)是字节的源或目的。两种基本的流是:输入流(Input Stream)和输出流(Output Stream)。可从中读出一系列字节的对象称为输入流。而能向其中写入一系列字节的对象称为输出流。流的分类节点流:从特定的地方读写的流类,例如:磁盘或一块内存区域。过滤流:使用节点流作为输入或输出。过滤流是使用一个已经存在的输入流或输出流连接创建的。InputStream三个基本的读...

weixin_30776737的博客 207

深度学习工具包 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")

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

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

DataInputStream 和 DataOutputStream流

1. 简介 DataInputStream 和 DataOutputStream流是基于 InputStream流 和 OutputStream流衍生出的子类,当然他们还基于父类DataInput 和 DataOutput。它们是针对Java基本数据类型读取/写入操作的。这两个类读写的文件都是针对机器的,DataOutputStream写出去的数据不是给人看的是给机器看的。而DataInputStream只能读取DataOutputStream写出去的文件。 使用DataOutputStream流写入t

weixin_43808717的博客 2687

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

DataInputStream 源码分析

DataInputStream 介绍 DataInputStream 是数据输入流。它继承于FilterInputStream。 DataInputStream 是用来装饰其它输入流,它“允许应用程序以与机器无关方式从底层输入流中读取基本 Java 数据类型”。应用程序可以使用DataOutputStream(数据输出流)写入由DataInputStream(数据输入流)读取的数据。 Dat

地平线的专栏 1389

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Java IO 技术之基本流类

Java IO 技术之基本流类 2011年03月08日   转自http://www.blogjava.net/coderdream/articles/65609. html 很好的一篇文章,谢谢作者   流式IO   流(Stream)是字节的源或目的。      两种基本的流是:输入流(Input Stream)和输出流(Output Stream)。可从中读出一系列字...

nng13nng 161

Java之文件IO

Java之文件IO

smart_ferry的博客 993

java语言编程IO流之DataInputStream与DataOutputStream

/*  时间:2015年3月10日16:58:18  测试DataOutputStream和DataOutputStream    DataInputStream和DataOutputStream分别继承自InputStream和OutputStream,它们是处理流,相应的需要套接在InputStream和OutputStream类型的节点流上  //输入流  ByteArrayIn

不当初 806

IO流 数据流 DataInputStream DataOutputStream

package io03; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import...

LY_yhq 169

IO包中的其他类总结

一、PrintStream和PrintWriter PrintStream 为其他输出流添加了功能,使它们能够方便地打印各种数据值表示形式。 PrintStream 打印的所有字符都使用平台的默认字符编码转换为字节。 在需要写入字符而不是写入字节的情况下,应该使用 PrintWriter 类。 1 /** 2 * PrintStream 3 * 1.提供了打印方法,可以对多种类型值进行

Brighten的的博客 376

[Java 12 IO] File 类 的几个基本操作

第 12 章 Java IO (最重要的五个类 和一个接口, File, OutputStream, InputStream, Writer, Reader, 接口: Serializable) 1, 掌握 java io 包中的继承关系 2, 可以使用 File 类进行文件的操作 3, 可以使用 字节流 或 字符流 操作文件内容并区分出字节流与字符流的区别 4...

anchang7456的博客 112
上一篇: Java 日看一类(10)之IO包中的DataInput接口
下一篇: Java 日看一类(12)DataOutput接口与DataOutputStream类
wyf95278
博客等级 码龄10年 38粉丝 71原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值