java IO笔记(FileDescriptor)

详解Java中的File文件类以及FileDescriptor文件描述类 在Java中File类可以用来新建文件和目录对象,而FileDescriptor类则被用来表示文件或目录的可操作性,接下来我们就来详解Java中的File文件类以及FileDescriptor文件描述类 立即下载

由于在看io源码中偶尔看到FileDescriptor,所以本篇决定讲讲FileDescriptor,从字面上来看它就是文件描述符。
官方是这么描述的:


可以看出,FileDescriptor可以看做一种指向文件引用的抽象化概念。它能表示一个开放文件,一个开放的socket或者一个字节的源。它最主要的用途就是去创建FileInputStream或者FileOutputStream。并且也说了不应该创建应用自己的文件描述符。

不得不说每次看这种官方的解释都表示云里雾里,毕竟与那些大神们差距太大,只能细细品味了。

不知道还是否记得前面讲述的System.out,System.in,System.error了,当时它们初始化的时候就用到了FileDescriptor:

当时没有细说,本篇则来探索一下FileDescriptor。

下面先贴上源码,通过源码来进行一定程度地学习:

package java.io;

import java.util.ArrayList;
import java.util.List;

public final class FileDescriptor {
    //封装了一个int型的值fd,每个打开的文件,socket等都会给你一个fd值,通过该值可以对文件,socket等进行相关操作,有点儿类似操作对象的索引
    private int fd;
    //
    private Closeable parent;
    //
    private List<Closeable> otherParents;
    //封装了一个boolean类型变量closed,用来判断fd是否被释放
    private boolean closed;

    //不带参构造,默认fd为-1,目测-1没什么意义,符合官方说的不建议直接创建自己的对象
    public /**/ FileDescriptor() {
        fd = -1;
    }

    //一个带参私有的构造方法,将fd值设为传入的参数
    private /* */ FileDescriptor(int fd) {
        this.fd = fd;
    }

    //定义的一个标准输入,fd值为0
    public static final FileDescriptor in = new FileDescriptor(0);

    //定义的一个标准输出,fd值为1
    public static final FileDescriptor out = new FileDescriptor(1);

    //定义的一个标准错误输出,fd值为2,我想在不同的环境下,标准流都能工作的原因应该就是因为已经在这里限定好了吧
    public static final FileDescriptor err = new FileDescriptor(2);
    

    //判断是否有效,这也证实了前面构造函数中fd赋值为-1是无效的
    public boolean valid() {
        return fd != -1;
    }

    public native void sync() throws SyncFailedException;

    /* This routine initializes JNI field offsets for the class */
    private static native void initIDs();

    static {
        initIDs();
    }

    // Set up JavaIOFileDescriptorAccess in SharedSecrets
    static {
        sun.misc.SharedSecrets.setJavaIOFileDescriptorAccess(
            new sun.misc.JavaIOFileDescriptorAccess() {
                public void set(FileDescriptor obj, int fd) {
                    obj.fd = fd;
                }

                public int get(FileDescriptor obj) {
                    return obj.fd;
                }

                public void setHandle(FileDescriptor obj, long handle) {
                    throw new UnsupportedOperationException();
                }

                public long getHandle(FileDescriptor obj) {
                    throw new UnsupportedOperationException();
                }
            }
        );
    }

    //像otherParents集合中添加元素
    synchronized void attach(Closeable c) {
        if (parent == null) {
            // first caller gets to do this
            parent = c;
        } else if (otherParents == null) {
            otherParents = new ArrayList<>();
            otherParents.add(parent);
            otherParents.add(c);
        } else {
            otherParents.add(c);
        }
    }

    //关闭otherParents所有的元素
    @SuppressWarnings("try")
    synchronized void closeAll(Closeable releaser) throws IOException {
        if (!closed) {
            closed = true;
            IOException ioe = null;
            try (Closeable c = releaser) {
                if (otherParents != null) {
                    for (Closeable referent : otherParents) {
                        try {
                            referent.close();
                        } catch(IOException x) {
                            if (ioe == null) {
                                ioe = x;
                            } else {
                                ioe.addSuppressed(x);
                            }
                        }
                    }
                }
            } catch(IOException ex) {
                /*
                 * 
                 */
                if (ioe != null)
                    ex.addSuppressed(ioe);
                ioe = ex;
            } finally {
                if (ioe != null)
                    throw ioe;
            }
        }
    }
}
因为笔者也是一个初学者,看了源码后,也没有发现什么,只是知道了下其中定义了3个标准分别为in,out,err,java中的标准流就是通过这里来实现的。其次就是fd的值不是我们可以随意修改的,是底层给我们的,我们可以通过该值取进行操作。并且FileDescriptor中需要进行close方法执行,应该是对文件等操作结束后,执行完close以后,才真正释放该索引以及对应的内存读写空间。

下面用1个小例子来展示一下FileDescriptor的使用及特性:

package test;

import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test4 {
	public static void main(String[] args) throws IOException {
		FileOutputStream fos = new FileOutputStream(FileDescriptor.out);
		fos.write("FileDescriptor:这里证明了System.out,就是使用FileDescriptor.out来创建的\r".getBytes());
		System.out.println("System.out:控制台输出");
		FileOutputStream fos1 = new FileOutputStream("./src/file/test.txt");
		FileOutputStream fos2 = new FileOutputStream("./src/file/test.txt");
		System.out.println("fos1:"+fos1.getFD());
		System.out.println("fos2:"+fos2.getFD());
		fos.close();
		fos1.close();
		fos2.close();
	}
}
执行上述代码可以在控制台看到如下打印:


第一句是一个使用了FileDescriptor.out创建的一个输出流打印出来,第二句为System.out打印出来的,两个流都是在控制台输出,再次证实了Sytem的in,out,err是通过FileDescriptor中的in,out,err来实现的。

然后我们看到对同一文件建立的两个不同的流,其fd值是不同的。

最后总结一下,这个类我们好像不怎么能使用到,因为我们无法去定义其中的fd值,所以我们能使用的基本只有其中为我们定义好的in,out,err了,但是众所周知,java已将帮我们封装好了更方便的System.in/out/err了,所以平常我们基本见不到其使用,只有在看源码时,会经常碰到了。

以上为本篇的内容。

从拆箱到跑通:Intel RealSense D435i开箱实测+ROS驱动配置全流程 本文详细记录了Intel RealSense D435i深度相机的开箱体验,并提供了在Ubuntu 22.04与ROS2 Humble环境下,从安装librealsense2 SDK到配置ROS2驱动的完整流程。重点解决了驱动安装、数据流发布、点云对齐以及IMU数据融合等关键步骤,帮助研究者和开发者快速实现D435i与机器人系统的集成。 阅读详情

相关推荐

Vivado固化程序与Flash型号添加实战指南

本文详细介绍了Vivado程序固化到Flash芯片的完整流程,包括基础操作、Flash型号添加方法及疑难问题排查。针对Vivado官方支持列表缺失的Flash型号,提供了手动添加配置的详细步骤和参数说明,并分享了高级技巧与安全操作建议,帮助开发者高效完成FPGA程序固化。

weixin_29291573的博客 565

FileDescriptor(文件描述符 )

内核(kernel)利用文件描述符(file descriptor)来访问文件。文件描述符是非负整数。打开现存文件或新建文件时,内核会返回一个文件描述符。读写文件也需要使用文件描述符来指定待读写的文件。 文件描述符在形式上是一个非负整数。实际上,它是一个索引值,指向内核为每一个进程所维护的该进程打开文件的记录表。

lzf的博客 1万+

告别功能限制:Win11家庭版无损升级专业版全攻略

本文详细介绍了如何将Win11家庭版无损升级到专业版的全过程,包括升级前的准备、两种官方升级方案(Microsoft Store购买和使用产品密钥)以及命令行升级方法。升级后可解锁远程桌面、组策略编辑器和BitLocker加密等高级功能,适合需要更多商业功能的用户。

weixin_32822843的博客 699

java descriptor_java io系列09之 FileDescriptor总结

本章对FileDescriptor进行介绍FileDescriptor 介绍FileDescriptor 是“文件描述符”。FileDescriptor 可以被用来表示开放文件、开放套接字等。以FileDescriptor表示文件来说:当FileDescriptor表示某文件时,我们可以通俗的将FileDescriptor看成是该文件。但是,我们不能直接通过FileDescriptor对该文件进行...

weixin_29779159的博客 487

改进爬山算法之六:随机重启爬山算法(Random-Restart Hill Climbing,RRHC)

随机重启爬山算法(Random-Restart Hill Climbing,RRHC)是爬山算法的一种改进策略,是一种启发式搜索算法,旨在通过随机重启来克服传统爬山算法容易陷入局部最优解的局限性,并增加找到全局最优解的概率。随机重启爬山算法通过在多次运行中不断尝试不同的初始解,并在每次运行中执行标准的爬山算法,最终选择所有运行中找到的最佳解作为最终结果。(1)计算复杂度:由于需要多次运行爬山算法,因此算法的计算复杂度可能较高,特别是在解空间较大或每次迭代需要较长时间的情况下。

搏博的专栏 2204

win10 运行lisflood_8踩过的坑

1、安装cuda及VS2019 https://www.bilibili.com/read/cv7335974/ 2、netcdf.h头文件找不到问题 https://www.cnblogs.com/lyggqm/p/12926974.html https://blog.youkuaiyun.com/u011954296/article/details/54617048 3、编码问题 https://blog.youkuaiyun.com/qq_33485434/article/details/81196843 4、

我的笔记 4115

【Java原理系列】 FileDescriptor原理用法源码分析

是一个文件描述符类,它作为对底层机器特定结构的不透明句柄,表示一个打开的文件、打开的套接字或其他字节源或接收器。主要实际用途是创建或。应用程序不应该自己创建文件描述符。int fd:文件描述符的整数值。:文件描述符的长整型值。:关联的Closeable对象,用于跟踪引用此文件描述符的其他对象。:与此文件描述符共享的其他Closeable对象列表。:标记文件描述符是否已关闭。:构造一个(无效的)对象。:标准输入流的文件描述符。:标准输出流的文件描述符。:标准错误流的文件描述符。

wang2leee的博客 667

DSP28377内存不够用?手把手教你合并RAM/FLASH块,解决CCS20链接器报错

本文详细介绍了在CCS20开发环境中解决DSP28377内存不足问题的方法,通过合并RAM/FLASH块优化CMD文件配置,有效解决链接器报错。文章包含内存布局对比、改写步骤、FreeRTOS集成注意事项及调试技巧,帮助开发者提升内存利用率与项目性能。

weixin_42524762的博客 143

FileDescriptor详解

FileDescriptor 介绍 FileDescriptor 是“文件描述符”。 FileDescriptor 可以被用来表示开放文件、开放套接字等。 以FileDescriptor表示文件来说:当FileDescriptor表示某文件时,我们可以通俗的将FileDescriptor看成是该文件。但是,我们不能直接通过FileDescriptor对该文件进行操作;若需要通过FileDescriptor对该文件进行操作,则需要新创建FileDescriptor对应的FileOutputStream,再对文

weixin_45439637的博客 1416

【论文精读】Latent Diffusion

Latent Diffusion

weixin_44934783的博客 4476

YOLOv5源码逐行超详细注释与解读(3)——训练部分train.py

全网最详细的YOLOv5项目源码解读之训练部分train. py。全文近5万字!代码逐行注释,逐段讲解,小白入门必备!

路人贾的博客 3万+

java filedescriptor_java IO笔记(FileDescriptor)

由于在看io源码中偶尔看到FileDescriptor,所以本篇决定讲讲FileDescriptor,从字面上来看它就是文件描述符。官方是这么描述的:可以看出,FileDescriptor可以看做一种指向文件引用的抽象化概念。它能表示一个开放文件,一个开放的socket或者一个字节的源。它最主要的用途就是去创建FileInputStream或者FileOutputStream。并且也说了不应该创建...

weixin_28749997的博客 649

【人工智能】提示词工程:让大模型精准响应的核心技术,提示词的基础框架 以及 常见提示词框架及场景

编写提示词的基础原则包括:简单、明确、详细,提示词拥有零样本提示、少样本提示、分配角色、提示写作风格、限定输出格式等技巧。

奶爸的编程之路,也就一周冷个三天 1138

java filedescriptor_Java IO(三)FileDescriptor

Java IO(三)FileDescriptor一、介绍FileDescriptor 是文件描述符,用来表示开放文件、开放套接字等。当 FileDescriptor 表示文件时,我们可以通俗的将 FileDescriptor 看成是该文件,但是不能直接通过 FileDescriptor 对该文件进行操作,若要通过 FileDescriptor 对该文件进行操作,则需要新创建 FileDescrip...

weixin_26759093的博客 444

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

java filedescriptor_java io系列09之 FileDescriptor总结

本章对FileDescriptor进行介绍FileDescriptor 介绍FileDescriptor 是“文件描述符”。FileDescriptor 可以被用来表示开放文件、开放套接字等。以FileDescriptor表示文件来说:当FileDescriptor表示某文件时,我们可以通俗的将FileDescriptor看成是该文件。但是,我们不能直接通过FileDescriptor对该文件进行...

weixin_30989583的博客 936

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Java IO流之文件描述符FileDescriptor

简介 POSIX标准 先了解一下POSIX标准,POSIX标准是操作系统为应用程序提供的接口,是电子和电气工程协会(简称IEEE)为要在各种UNIX操作系统上运行软件而定义的一系列API标准总称,目的是为了保证应用程序的可移植性.也就是说为一个POSIX操作系统编写的应用程序,在另外一个POSIX操作系统里面依旧可以运行.比如:POSIX标准接口:Open()打开文件,create()创建文件...

梦悠哉的博客 3337

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

Java io FileDescriptor介绍及使用

FileDescriptor 介绍 FileDescriptor 是“文件描述符”。 FileDescriptor 可以被用来表示开放文件、开放套接字等。 以FileDescriptor表示文件来说:当FileDescriptor表示某文件时,我们可以通俗的将FileDescriptor看成是该文件。但是,我们不能直接通过FileDescriptor对该文件进行操作;若需要通过FileDes

Seachal的博客 9302

java filedescriptor,从Java中的FileDescriptor获取路径

Some quick background on my problem:I'm writing a compiler that converts Domain Type Enforcement specs into Java Security Manager code. In a nutshell, DTE defines "types" (objects), assigns paths to t...

weixin_39558804的博客 576

Java FileDescriptor sync()方法与示例

FileDescriptor类sync()方法 (FileDescriptor Class sync() method) sync() method is available in java.io package. sync()方法在java.io包中可用。 sync() method is used to synchronize all the system buffer with the...

cumtb2002的博客 887

FileDescriptor解读

FileInputStream、FileOutputStream、SocketInputStream、SocketOutputStream中都有一个FileDescriptor对象,我们可以将这个文件描述符对象类比为我们要操作的文件在JVM中的一个句柄,但是这个句柄并没有实际对文件进行操作的动作,要想读取或者写入文件只能创建对象的输入流和输出流对象,FileDescriptor在输入输出流对象当中

yzq234040228的专栏 2733

Java IO (15) -- FileDescriptor 类

文章目录1. 概念2. 字段3. 方法1. 构造器2. 其他方法4. 案例 1. 概念 2. 字段 3. 方法 1. 构造器 2. 其他方法 4. 案例

南京的博客 404

Java FileDescriptor源码理解和三个标准流

Java FileDescriptor源码理解简介FileDescriptor类参数及构造三个标准流 简介 java中的File类是无法对文件进行操作的,只有通过FileInputStream和FileOutputStream才能对文件进行操作。 public FileInputStream(File file) throws FileNotFoundException { String name = (file != null ? file.getPath() : null);

zhanghl的博客 1037

java descriptor_Java中的Java.io.FileDescriptor - Break易站

sync():java.io.File.sync()将所有缓冲区与基础设备同步。当FileDescriptor的所有修改数据都已写入底层设备时,该方法返回。句法 :public void sync()Parameters :-----------Return :voidException :-> SyncFailedException :This is exception is thrown...

weixin_28876083的博客 193

java filedescriptor_Java FileDescriptor sync()方法

Java FileDescriptor sync()方法java.io.File.sync()方法强制所有系统缓冲区与基础设备同步。1 语法public void sync()2 参数无3 返回值无4 示例package com.yiidian;/*** 一点教程网: http://www.yiidian.com*//*** java.io.File.sync()方法的例子*/import ja...

weixin_42497762的博客 579
上一篇: java IO笔记(DataInput/DataOutput)
下一篇: JavaScript学习笔记(DOM脚本)
moonfish0607
博客等级 码龄11年 26粉丝 50原创
评论 5
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

打赏作者

moonfish0607

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值