ResourceLoaderDemo.java 804 B

123456789101112131415161718192021222324
  1. package com.lovecoding.resources;
  2. import org.springframework.context.support.ClassPathXmlApplicationContext;
  3. import org.springframework.core.io.Resource;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. public class ResourceLoaderDemo {
  7. public static void main(String[] args) {
  8. ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
  9. Resource resource = context.getResource("classpathdemo.properties");
  10. InputStream inputStream = null;
  11. try {
  12. inputStream = resource.getInputStream();
  13. byte[] n = new byte[1024];
  14. while ( inputStream.read(n) != -1 ) {
  15. System.out.println( new String(n) );
  16. }
  17. } catch (IOException e) {
  18. e.printStackTrace();
  19. }
  20. }
  21. }