import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
/**
* java,两个简单实用的高效程序 1、InputStream与OutputStream实现文件(任何类型文件)复制功能 2、高效遍历Map
*
* @author Lance
* @date 2010-06-10 18:14
*/
public class JavaCode {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
copy();
lookMap();
}
/**
* 二进制流拷贝文件
*
* @return
*/
public static boolean copy() {
try {
OutputStream os = new FileOutputStream("C://testCopy.rar");
InputStream fis = new FileInputStream("C://test.rar");
byte[] buf = new byte[255];
int len = 0;
while ((len = fis.read(buf)) != -1) {
os.write(buf, 0, len);
}
fis.close();
os.flush();
os.close();
return true;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
/**
* 高效遍历Map
*/
public static void lookMap() {
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("aaaa", 1);
map.put("bbbb", 2);
map.put("cccc", 3);
map.put("dddd", 4);
map.put("eeee", 5);
Set<Entry<String, Integer>> set = map.entrySet();
for (Entry<String, Integer> entry : set) {
System.out.println(entry.getKey() + "=" + entry.getValue());
}
}
}