auto commit
This commit is contained in:
commit
3c6be1aa1e
@ -69,16 +69,17 @@ public static void listAllFiles(File dir) {
|
|||||||
|
|
||||||
```java
|
```java
|
||||||
public static void copyFile(String src, String dist) throws IOException {
|
public static void copyFile(String src, String dist) throws IOException {
|
||||||
|
|
||||||
FileInputStream in = new FileInputStream(src);
|
FileInputStream in = new FileInputStream(src);
|
||||||
FileOutputStream out = new FileOutputStream(dist);
|
FileOutputStream out = new FileOutputStream(dist);
|
||||||
|
|
||||||
byte[] buffer = new byte[20 * 1024];
|
byte[] buffer = new byte[20 * 1024];
|
||||||
|
int cnt;
|
||||||
|
|
||||||
// read() 最多读取 buffer.length 个字节
|
// read() 最多读取 buffer.length 个字节
|
||||||
// 返回的是实际读取的个数
|
// 返回的是实际读取的个数
|
||||||
// 返回 -1 的时候表示读到 eof,即文件尾
|
// 返回 -1 的时候表示读到 eof,即文件尾
|
||||||
while (in.read(buffer, 0, buffer.length) != -1) {
|
while ((cnt = in.read(buffer, 0, buffer.length)) != -1) {
|
||||||
out.write(buffer);
|
out.write(buffer, 0, cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
in.close();
|
in.close();
|
||||||
|
@ -196,7 +196,7 @@ String 不可变性天生具备线程安全,可以在多个线程中安全地
|
|||||||
|
|
||||||
## String Pool
|
## String Pool
|
||||||
|
|
||||||
字符串常量池(String Pool)保存着所有字符串字面量(literal strings),这些字面量在编译时期就确定。不仅如此,还可以使用 String 的 intern() 方法在运行过程中将字符串添加到 String Poll 中。
|
字符串常量池(String Pool)保存着所有字符串字面量(literal strings),这些字面量在编译时期就确定。不仅如此,还可以使用 String 的 intern() 方法在运行过程中将字符串添加到 String Pool 中。
|
||||||
|
|
||||||
当一个字符串调用 intern() 方法时,如果 String Pool 中已经存在一个字符串和该字符串值相等(使用 equals() 方法进行确定),那么就会返回 String Pool 中字符串的引用;否则,就会在 String Pool 中添加一个新的字符串,并返回这个新字符串的引用。
|
当一个字符串调用 intern() 方法时,如果 String Pool 中已经存在一个字符串和该字符串值相等(使用 equals() 方法进行确定),那么就会返回 String Pool 中字符串的引用;否则,就会在 String Pool 中添加一个新的字符串,并返回这个新字符串的引用。
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user