Hello World

写代码的流程

数组

初始化数组(Inline array initialization)

常用的数组处理代码 Typical array-processing code

二维数组Two-dimensional arrays

内联初始化Inline initialization

类Class/class

文件
复制文件
public static void copyFile(File from, File to) throws IOException { File[] children = from.listFiles(); if (children == null || children.length == 0) { if (from.isDirectory()) { to.mkdirs(); } else { to.getParentFile().mkdirs(); Files.copy(from.toPath(), to.toPath(), StandardCopyOption.REPLACE_EXISTING); } } else { for (File child : children) { copyFile(child, new File(to, child.getName())); } } }
移动(move)文件
public static void moveFile(File from, File to) throws IOException { Files.move(from.toPath(), to.toPath(), StandardCopyOption.REPLACE_EXISTING); }
读文件
public static List<String> readLines(File file) throws IOException { List<String> lines = new ArrayList<String>(); try (BufferedReader br = new BufferedReader(new FileReader(file))) { String line = br.readLine(); while (line != null) { lines.add(line); line = br.readLine(); } } return lines; }