1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
public class Demo01 {
public static void main(String[] args) throws IOException {
File file = new File("test.txt");
byte[] bytes = FileUtils.readFileToByteArray(file); System.out.println(new String(bytes)); String s = FileUtils.readFileToString(file); System.out.println(s); String s1 = FileUtils.readFileToString(file, "UTF-8"); System.out.println(s1); List readLines = FileUtils.readLines(file);
for (Object l:readLines ) { System.out.println("-----"+l); } List<Object> objects = new ArrayList<Object>(); objects.add(1); objects.add("上海"); objects.add("北京"); FileUtils.writeLines(new File("test1.txt"),objects); FileUtils.writeStringToFile(new File("test1.txt"),"什么时候我才能技术达到最佳"); FileUtils.writeByteArrayToFile(new File("test1.txt"),"我想一个人成长".getBytes()); } }
|