FileUtil1 读取文件内容

 

View Code
 1 package com.cici.readfile;

 2 

 3 import java.io.DataInputStream;

 4 import java.io.File;

 5 import java.io.FileInputStream;

 6 import java.io.IOException;

 7 import java.net.URL;

 8 

 9 public class Utilities {

10     

11     

12     private Utilities(){}

13     

14     //文件的相对路径

15     public final static String XML_PATH = "/xml/";

16     public static void testGetFile(String filePath) throws IOException{

17         URL filepath = Utilities.class.getResource(XML_PATH+filePath);

18         String fileFullPath = filepath.getFile();

19         File dir = new File(fileFullPath);

20         int i; 

21         if(dir.isDirectory()){

22             //遍历该目录

23             File[] subFiles = dir.listFiles();

24             for(File file: subFiles){

25                 if(file.isFile()){

26                     FileInputStream input = new FileInputStream(file);

27                        //3.以文件输入流对象为参数创建数据输入流对象   

28                     DataInputStream dis=new DataInputStream(input);  

29                     //4.读取其他文件的内容并输出   

30                     System.out.println("=============="+file.getName()+"===============");

31                     while((i=input.read())!=-1)  

32                     {  

33                         System.out.print((char)i);  

34                     } 

35                     System.out.println("===============================================");

36                 } 

37             }

38      }

39     }

40      public static void main(String[] args) throws IOException {

41         String path = "conf";

42          testGetFile(path) ;

43     }

44 }

 

 

 

 

你可能感兴趣的:(fileutil)