我试图找到一种以最快的方式复制大文件的方法......
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
public class FastFileCopy {
public static void main(String[] args) {
try {
String from = "...";
String to = "...";
FileInputStream fis = new FileInputStream(from);
FileOutputStream fos = new FileOutputStream(to);
ArrayList<Transfer> transfers = new ArrayList<>();
long position = 0, estimate;
int count = 1024 * 64;
boolean lastChunk = false;
while (true) {
if (position + count < fis.getChannel().size()) {
transfers.add(new Transfer(fis, fos, position, position + count));
position += count + …Run Code Online (Sandbox Code Playgroud) 你好,我怎么能改变一个键的值HashMap?
请看这个:
private static final Map<String, DefaultMutableTreeNode> M = new HashMap<>();
public static DefaultMutableTreeNode executeCommand(int command, String item1, String item2) {
switch (command) {
//...
case CommandsList.CREATE_CHILD:
String name = item1;
M.put(name, new DefaultMutableTreeNode(name));
//...
return M.get(root);
case CommandsList.CHANGE_NAME:
String newName = item2;
//
//what should I do here to replace name with newName???
//
return M.get(root);
//...
}
return null;
}
Run Code Online (Sandbox Code Playgroud)