Spring Resource文件操作接口

Spring整理系列(07)——通过Spring Resource接口获取资源 一、Resources介绍Resources :获取资源文件的统一接口。二、Resources接口主要实现类有 ClassPathResource:获取类路径下的资源文件 UrlResource:URL对应的资源,根据一个URL地址即可创建 FileSystemResource:获取文件系统里面的资源 ServletContextResource:ServletContext封装的资源,用于访问 S 阅读详情

 

Spring中获取资源的方式一共有以下四种:

  1. 通过Resource接口获取资源
  2. 通过ResourceLoader接口获取资源
  3. 通过ApplicationContext获取资源
  4. 将resource注入到bean中的方式获取资源

下面是对每种方式的详细讲解 :

1.通过Resource接口获取资源


                           Resource接口的实现类有:

实现类  说明
ClassPathResource通过类路径获取资源文件
FileSystemResource通过文件系统获取资源
UrlResource通过URL地址获取资源
ByteArrayResource获取字节数组封装的资源
ServletContextResource获取ServletContext环境下的资源
InputStreamResource取输入流封装的资源

 

Resource接口继承了InputStreamSource 接口,InputStreamSource 接口中有一个方法:getInputStream(),所以汇总起来,Resource接口中共有以下方法:


exists()  
判断资源是否存在,true表示存在。
isReadable()  判断资源的内容是否可读。需要注意的是当其结果为true的时候,其内容未必真的可读,但如果返回
 isOpen()判断当前Resource代表的底层资源是否已经打开,如果返回true,则只能被读取一次然后关闭以避免资源泄露;该方法主要针对于InputStreamResource,实现类中只有它的返回结果为true,其他都为false
getURL()返回当前资源对应的URL。如果当前资源不能解析为一个URL则会抛出异常。如ByteArrayResource就不能解析为一个URL。
getURI()    返回当前资源对应的URI。如果当前资源不能解析为一个URI则会抛出异常。
getFile()    返回当前资源对应的File。
contentLength()  返回当前资源内容的长度。
lastModified()    返回当前Resource代表的底层资源的最后修改时间。
createRelative()   根据资源的相对路径创建新资源。[默认不支持创建相对路径资源]
getFilename()    获取资源的文件名。
getDescription()   返回当前资源底层资源的描述符,通常就是资源的全路径(实际文件名或实际URL地址)。
getInputStream()    获取当前资源代表的输入流。除了InputStreamResource实现类以外,其它Resource实现类每次调用getInputStream()方法都将返回一个全新的InputStream。


演示代码:  
 

public class ResourceTest {

    /**使用ClassPathResource获取资源**/
    @Test
    public void TestClassPath() throws IOException{
        Resource resource = new ClassPathResource("test.txt");

        //判断文件是否存在:
        if (resource.exists()) {
            System.out.println("文件存在");
        }

        //判断资源文件是否可读
        if (resource.isReadable()) {  
            System.out.println("文件可读"); 
        }

        //判断当前Resource代表的底层资源是否已经打开
        if (resource.isOpen()) {
            System.out.println("资源文件已打开");
        }

        System.out.println(resource.getURL());//获取资源所在的URL
        System.out.println(resource.getURI());//获取资源所在的URI
        resource.getFile();//返回当前资源对应的File。
        System.out.println(resource.contentLength());//输出内容长度
        System.out.println(resource.lastModified());//返回当前Resource代表的底层资源的最后修改时间。
        resource.createRelative("MyFile");//根据资源的相对路径创建新资源。[默认不支持创建相对路径资源]
        System.out.println(resource.getFilename());//获取资源文件名
        System.out.println(resource.getDescription());


        //获取当前资源代表的输入流
        if (resource.isReadable()) {
            InputStream is = resource.getInputStream();  
            System.out.println(is);
            is.close();
        }

    }

    /**使用FileSystemResource获取资源**/
    @Test
    public void TestFileSystem() throws IOException {
        Resource resource = new FileSystemResource("D:\\test.txt");
        System.out.println(resource.getFilename());
    }

    /**使用UrlResource获取资源**/
    @Test
    public void TestUrl() throws MalformedURLException{
        Resource resource = new UrlResource("http://docs.spring.io/spring/docs/4.0.0.M1/spring-framework-reference/pdf/spring-framework-reference.pdf");
        System.out.println(resource.getFilename());
    }

    /**使用ByteArrayResource获取字节数组封装的资源**/
    @Test
    public void testByteArray() throws IOException {
        ByteArrayResource resource = new ByteArrayResource("Hello".getBytes()); 
        System.out.println(resource.getInputStream());

    }


    /**使用InputStreamResource获取输入流封装的资源。针对于输入流的Resource,其getInputStream()方法只能被调用一次。**/  
       @Test  
       public void testInputStream() throws Exception {  
          InputStream is = new FileInputStream("D\\test.txt");  
          InputStreamResource resource = new InputStreamResource(is);  
          //对于InputStreamResource而言,其getInputStream()方法只能调用一次,继续调用将抛出异常。  
          InputStream is2 = resource.getInputStream();   //返回的就是构件时的那个InputStream
          System.out.println(is2);
          is.close();
       } 

}

2.通过ResourceLoader接口获取资源


Spring框架为了更方便的获取资源,尽量弱化程序员对各个Resource接口的实现类的感知,定义了另一个ResourceLoader接口。该接口的getResource(String location)方法可以用来获取资源。它的DefaultResourceLoader实现类可以适用于所有的环境,可以返回ClassPathResource、UrlResource等。

ResourceLoader在进行加载资源时需要使用前缀来指定需要加载:“classpath:path”表示返回ClasspathResource,“http://path”和“file:path”表示返回UrlResource资源,如果不加前缀则需要根据当前上下文来决定,DefaultResourceLoader默认实现是加载classpath资源。 
示例代码:
 

       @Test  
       public void testResourceLoader() { 

              ResourceLoader loader = new DefaultResourceLoader();  
              Resource resource = loader.getResource("http://www.baidu.com");  
              System.out.println(resource instanceof UrlResource); //true  
              resource = loader.getResource("classpath:test.txt");  
              System.out.println(resource instanceof ClassPathResource); //true  
              resource = loader.getResource("test.txt");  
              System.out.println(resource instanceof ClassPathResource); //true  

       } 

3.通过ApplicationContext获取资源


事实上,所有ApplicationContext实例都实现了ResourceLoader接口,因此我们在使用Spring容器时,可以不去过于计较底层Resource的实现,也不需要自己创建Resource实现类,而是直接使用applicationContext.getResource(),获取到bean容器本身的Resource,进而取到相关的资源信息。 
示例代码: 
首先创建一个MyResource类:这个类实现了ApplicationContextAware接口来获取上下文对象
 

public class MyResource implements ApplicationContextAware {
        private ApplicationContext applicationContext;

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public void resource() throws IOException {
        Resource resource = applicationContext.getResource("file:D:\\test.txt");
        System.out.println(resource.getFilename());
        System.out.println(resource.contentLength());

    }

}

配置xml文件:

<bean id="myResource" class="com.spring.test.MyResource"></bean>

测试类:

public class App {
    public static void main(String[] args) {
        @SuppressWarnings("resource")
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-resource.xml");  
        MyResource myResource = (MyResource) context.getBean("myResource");
        try {
            myResource.resource();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

4.将resource注入到bean中的方式获取资源


通过依赖注入的方式把Resource注入到bean中。 
示例代码:

public class MyResource {
    private Resource resource;

    public void setResource(Resource resource) {
        this.resource = resource;
    }

    public void resource() throws IOException {
        System.out.println(resource.getFilename());
        System.out.println(resource.contentLength());
    }

}


配置spring-resource xml文件:

<bean id="myResource" class="com.spring.test.MyResource">
        <property name="resource">
            <value>classpath:test.txt</value>
        </property>
</bean>


测试类:

public class App {
    public static void main(String[] args) {
        @SuppressWarnings("resource")
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-resource.xml");  
        MyResource myResource = (MyResource) context.getBean("myResource");
        try {
            myResource.resource();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}


测试结果为:

è¿éåå¾çæè¿°

AlphaFold-multimer 复合物结构预测 是DeepMind开发的AlphaFold项目的一个扩展,旨在预测蛋白质多聚体的三维结构。蛋白质多聚体是由多个蛋白质亚单位相互组装而成的结构,如酶、膜蛋白复合物和病毒颗粒。理解多聚体的结构对于揭示蛋白质的功能和相互作用非常重要。 阅读详情

相关推荐

Windows如何使用Anaconda 3进行keras环境的配置

** Windows如何使用Anaconda 3进行keras环境的配置 搭建Keras环境* Anaconda3如何安装keras,主要包括下面三步: 1.安装mingw libpython 2.安装theano 3.安装keras 若你还没有按装anaconda,赶紧下载安装吧! 下载途径有两个 (1)Anaconda版本为Anaconda 4.4.0,对应的python版本为3.6,附上An...

Lance_liangliang的博客 1599

Springboot获取jar包中resources资源目录下的文件

Springboot获取jar包中resources资源目录下的文件

weixin_42585386的博客 9467

曙光服务器RAID配置避坑指南:MegaRAID SAS 9361-8i实战(含Foreign状态处理)

本文详细解析了曙光服务器搭配MegaRAID SAS 9361-8i控制器的RAID配置全流程,包括RAID0和RAID5的创建、Foreign状态处理及性能优化策略。特别针对磁盘迁移中的Foreign状态问题,提供了系统化的解决方案和高级恢复技巧,助力企业级IT运维提升存储配置的稳定性和可靠性。

weixin_29200741的博客 410

不看后悔系列-Spring源码(五):Resource、ResourceLoader接口体系

前面说过,IOC的构建分成三个步骤 1)资源定位:定位资源文件,比如xml 2)装载:将资源文件中的bean定义转换成BeanDefinition 3)BeanDefinition注册:将BeanDefinition注册进beanFactory 这一章就介绍有关一个步骤的基础知识 在Java万物皆对象的思想下,资源(包括配置文件,url,文件等等)也会被抽象成一个对象。 在Spring中,资...

qq_33366098的博客 426

【实战】S7-PLCSIM Advanced V3.0 授权问题排查指南(Error Code:-30与LicenseNotFound深度解析)

本文深度解析S7-PLCSIM Advanced V3.0启动时遇到的Error Code:-30与LicenseNotFound报错问题。文章提供了一套系统性的排查指南,从检查WinPcap驱动兼容性、确保Automation License Manager服务运行,到正确安装浮动授权以及清理系统残留缓存,逐步解决授权链条中的各个环节故障,帮助用户彻底解决仿真环境启动失败的问题。

weixin_29185167的博客 719

VNC Viewer建立多个图形界面,来远程访问同一个服务器(Ubuntu)

如题。目前已经有了一个VNC viewer连接,那么如果再开一个图形界面呢? 思路主要是:新建一个用户,从这个用户新建一个vnc连接,然后访问图形界面。

the Blog of 等不到天亮丶等时光 5897

Springboot使用ResourceUtils.getFile()读取resource下文件的坑

先说结论,使用ResourceUtils.getFile()方法读取resource下文件,在IDEA等开发工具场景下是没问题的,但是将服务达成jar包后,执行该方法就会包错文件找不到; 因此尽量不要使用该方法来读取文件,可以使用以下几种方式替代: ClassPathResource classPathResource = new ClassPathResource("excleTemplate/test.txt"); InputStream inputStream =classPathResource.

Mr__simon的博客 1万+

UE5接入在线直播视频源,如hls(m3u8)格式

UE5接入在线直播视频源

专注GIS开发 9496

Spring中Resource(资源)的获取

Spring中获取资源的方式一共有以下四种: 通过Resource接口获取资源 通过ResourceLoader接口获取资源 通过ApplicationContext获取资源 将resource注入到bean中的方式获取资源 下面是对每种方式的详细讲解 :1.通过Resource接口获取资源Resource接口的实现类有: 实现类 说明 ClassPathResource 通过类路径获

解忧杂货铺 1万+

论文必备 - YOLOv11热力图可视化,支持指定模型,指定显示层,设置置信度,以及10种可视化实现方式

本文带来的是YOLOv11热力图可视化功能,支持,以及。我们经常看到一些论文里绘制了不同的热力图,一方面能够直观的感受其模型的有效性,另一方面也丰富了论文内容。特别是在使用了注意力模块的网络中,热力图就可以验证注意力机制是否真正聚焦到了预期的重要特征上,以便对模型的有效性和合理性进行评估。例如这篇文章中展示的,就很能够表达作者改进后的模型相比之前模型的优越性。

Limiiiing的博客 5503

【深度学习】脸部修复,CodeFormer,论文,实战

Blind face restoration是一个高度 ill-posed 的问题,通常需要辅助引导来 1) 改善从降级输入到期望输出的映射,或者 2) 补充在输入中丢失的高质量细节。在本文中,我们展示了在一个小的代理空间中学到的离散码本先验可以通过将盲目的面部恢复建模为 a code prediction task来大大减少恢复映射的不确定性和模糊性,同时为生成高质量面部提供丰富的视觉元素。

q742971636的博客 2989

Resource接口解读

Resource是spring的资源策略接口,Resource定义了一套资源框架。spring提供了更加丰富的资源的定义。对不同来源的资源文件都有相应的 Resource 实现∶文件(FileSystemResource)、Classpath 资源(ClassPathResource)、URL 资源(UrlResource)、InputStream资源(InputStreamResource)、Byte 数组(ByteArrayResource)等Resource是spring的资源策略接口,Resourc

qq_43203949的博客 975

[Dify实战] 解决 Dify 导入 DSL 文件时报 “DSL 版本差异” 的兼容性问题

摘要:本文针对Dify开发者在导入.dsl文件时遇到的版本警告提示问题,分析其根源在于DSL文件与当前系统版本不一致。解决方案是通过导出当前Dify应用的DSL文件查看版本号,手动修改待导入文件的version字段以匹配。文章详细说明了操作步骤,并给出使用专业编辑器、避免修改其他字段等实用建议,帮助开发者规避版本不兼容问题,提升多模态AI应用开发效率。

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 960

String源码解读之Resource接口

一、前言 我们都知道java自身也提供了底层资源的方法,如(java.net.URL,File)等, 但是java所提供的并不支持访问web容器资源的类,因此spring在此次方面做了强大的扩展,设计了Resource接口,提供了更强的底层资源访问能力,也是spring重要的辅助类。Resource可以在完全不依赖spring容易的情况下运行,是个比较强大的资源访问类。 二、

912

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Spring 学习日记(三)Resource接口

在看Resource接口的时候遇到不小的理解为题 所以度娘了一下 http://haohaoxuexi.iteye.com/blog/2016305 厚颜无耻的转载一下 以备后用1 Resource简介 在Spring内部,针对于资源文件有一个统一的接口Resource表示。其主要实现类有ClassPathResource、FileSystemResource、UrlReso

大萌萌德 749

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

Spring常用工具类

文件资源操作 Spring 定义了一个 org.springframework.core.io.Resource 接口,Resource 接口是为了统一各种类型不同的资源而定义的,Spring 提供了若干 Resource 接口的实现类, 这些实现类可以轻松地加载不同类型的底层资源,并提供了获取文件名、URL 地址以及资源内容的操作方法 访问文件资源 通过 FileSystem

GarfieldEr007的专栏 1115

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Spring 的优秀工具类盘点

          Spring 不但提供了一个功能全面的应用开发框架,本身还拥有众多可以在程序编写时直接使用的工具类,您不但可以在 Spring 应用中使用这些工具类,也可以在其它的应用中使用,这些工具类中的大部分是可以在脱离 Spring 框架时使用的。了解 Spring 中有哪些好用的工具类并在程序编写时适当使用,将有助于提高开发效率、增强代码质量。 在这个分为两部分的文章中,我们...

六月 159

spring常用工具类

http://www.ibm.com/developerworks/cn/java/j-lo-spring-utils1/index.html 文件资源操作 Spring 定义了一个 org.springframework.core.io.Resource 接口,Resource 接口是为了统一各种类型不同的资源而定义的,Spring 提供了若干 Resource 接口的实现类,这些实现类可以...

iteye_10403的博客 114

Spring之资源访问

对于很多程序框架来讲,资源访问都是比较基础的。JDK提供了资源访问类(如java.net.URL、File类等)。但是它并不能很好的满足各种底层资源的访问需求,比如缺少从类路径或容器上下文中获取资源的操作类。Spring设计了一个Resource接口,类结构如下: 其实结构Resource 继承了InputStreamSource。所以,我们先看看InputStreamSource,代码

guoweiguoweiguo的专栏 974

Spring工具类详解

Spring 不但提供了一个功能全面的应用开发框架,本身还拥有众多可以在程序编写时直接使用的工具类,您不但可以在 Spring 应用中使用这些工具类,也可以在其它的应用中使用,这些工具类中的大部分是可以在脱离 Spring 框架时使用的。了解 Spring 中有哪些好用的工具类并在程序编写时适当使用,将有助于提高开发效率、增强代码质量。  文件资源操作  文件资源的操作是应用程序中常见的功能,如当

叶易风云 792

spring优秀工具类---1

Spring 不但提供了一个功能全面的应用开发框架,本身还拥有众多可以在程序编写时直接使用的工具类,您不但可以在 Spring 应用中使用这些工具类,也可以在其它的应用中使用,这些工具类中的大部分是可以在脱离 Spring 框架时使用的。了解 Spring 中有哪些好用的工具类并在程序编写时适当使用,将有助于提高开发效率、增强代码质量。 在这个分为两部分的文章中,我们将从众多的 Spring...

jiav_net的专栏 126

Spring 优秀工具盘点—第1部分

      Spring 不但提供了一个功能全面的应用开发框架,本身还拥有众多可以在程序编写时直接使用的工具类,您不但可以在 Spring 应用中使用这些工具类,也可以在其它的应用中使用,这些工具类中的大部分是可以在脱离 Spring 框架时使用的。了解 Spring 中有哪些好用的工具类并在程序编写时适当使用,将有助于提高开发效率、增强代码质量。 在这个分为两部分的文章中,我们将从众多的 Spr...

坚持而不浮躁 171

spring工具 ---读文件

<br />package com.wondersgroup.subject.common.util;<br />import java.io.File;<br />import java.io.FileReader;<br />import java.io.InputStream;<br />import org.springframework.core.io.ClassPathResource;<br />import org.springframework.core.io.FileSystemReso

heartdiamond的专栏 5487

spring源码学习过程(二)、资源定义深入

spring源码学习过程(二)、资源定义深入

anxinr的博客 147

Spring 源码---------Spring Core

Spring Resource接口是框架中用于统一访问各类资源的核心抽象,支持文件系统、类路径、URL等多种资源类型。它提供了exists()、getInputStream()等方法进行资源检测和读取,并包含ClassPathResource、FileSystemResource等多种实现。该接口与ResourceLoader等组件紧密配合,广泛应用于配置加载、静态资源处理等场景。使用时需注意路径处理、资源刷新等问题,针对不同场景选择合适的实现类可简化资源访问逻辑。

hi 383

(转)Spring 的优秀工具类盘点

第 1 部分: 文件资源操作和 Web 相关工具类 http://www.ibm.com/developerworks/cn/java/j-lo-spring-utils1/ 文件资源操作 文件资源的操作是应用程序中常见的功能,如当上传一个文件后将其保存在特定目录下,从指定地址加载一个配置文件等等。我们一般使用 JDK 的 I/O 处理类完成这些操作,但对于一般的应用程序来说,JD...

dianxianfei6692的博客 217
上一篇: Java写数据到TXT(满n行写入新TXT)
下一篇: XML解析 验证之XSD和DTD验证以及 SpringXML验证源码分析
大佛拈花
博客等级 码龄10年 2834粉丝 183原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值