| 107 | } |
| 108 | |
| 109 | public static void copyFile(String sourceFilename, String destFilename) { |
| 110 | File source = new File(sourceFilename); |
| 111 | if (!source.exists()) { return; } //if source doesn't exist, nothing to copy |
| 112 | |
| 113 | try (InputStream is = Files.newInputStream(source.toPath()); |
| 114 | OutputStream os = Files.newOutputStream(new File(destFilename).toPath())){ |
| 115 | byte[] buffer = new byte[1024]; |
| 116 | int length; |
| 117 | while ((length = is.read(buffer)) > 0) { |
| 118 | os.write(buffer, 0, length); |
| 119 | } |
| 120 | } |
| 121 | catch (Exception e) { |
| 122 | e.printStackTrace(); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | public static void writeFile(String filename, String text) { |
| 127 | FileUtil.writeFile(new File(filename), text); |