Created
May 5, 2017 14:14
-
-
Save BalicantaYao/ec3e6df523f3275582a9a3788a3b47bc to your computer and use it in GitHub Desktop.
讀取檔案內容範例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FolderRead { | |
public static void main(String[] args) throws IOException { | |
// files 路徑 | |
File files1 = new File("files"); | |
File[] files2 = files1.listFiles(); | |
for (File file : files2) { | |
String name = file.getName(); | |
// 方法一: | |
// FileUtils.readFileToString(file); | |
// 方法二: | |
FileInputStream inputStream = new FileInputStream(file); | |
String result = ""; | |
int content; | |
while ((content = inputStream.read()) != -1) { | |
char item = (char)content; | |
result +=item; | |
} | |
System.out.println(result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment