问题1
public class q1 {
public static void main(String[] args) throws Exception {
FileInputStream fis = new FileInputStream("E:\\TEXT\\bee.png");
BufferedInputStream bis = new BufferedInputStream(fis);
FileOutputStream fos = new FileOutputStream("E:\\TEXT1\\bee_copy.png");
BufferedOutputStream bos = new BufferedOutputStream(fos);
byte[] bytes = new byte[8096];
while (bis.read(bytes) != -1) bos.write(bytes);
bis.close();
bos.close();
fis.close();
fos.close();
}
}
问题2
public class q2 {
public static void main(String[] args) throws Exception {
URL url1 = new URL("https://img-blog.csdnimg.cn/41f84da3459a42f49b574f6732f69e08.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5o6S6aqo546J57Gz5rGk,size_20,color_FFFFFF,t_70,g_se,x_16");
URLConnection uc = url1.openConnection();
InputStream inputStream = uc.getInputStream();
BufferedInputStream bis = new BufferedInputStream(inputStream);
FileOutputStream fos = new FileOutputStream("E:\\TEXT\\download.png");
BufferedOutputStream bos = new BufferedOutputStream(fos);
byte[] bytes = new byte[8096];
int read = -1;
while ((read = bis.read(bytes)) != -1) bos.write(bytes, 0,read );
bis.close();
bos.close();
inputStream.close();
fos.close();
}
}
问题3
public class q3 {
public static void main(String[] args) {
String[] keys = {"黑龙江省", "浙江省", "江西省", "广东省", "福建省"};
String[] value = {"哈尔滨", "杭州", "南昌", "广州", "福州"};
Map<String,String> map = new HashMap<>();
for (int i = 0; i < keys.length; i++) {
map.put(keys[i],value[i]);
}
}
}
问题4
public class q4 {
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
for (int i = 0; i < 10; i++)
list.add((int) (Math.random() * 50));
list.set(1, list.get(2));
list.set(2, list.get(1));
int max = list.get(0);
int min = list.get(0);
for (int i : list) {
max = Math.max(max,i);
min = Math.min(min,i);
}
System.out.println("max = " +max);
System.out.println("min = " +min);
Iterator<Integer> iterator = list.iterator();
while (iterator.hasNext())
System.out.print(iterator.next()+" ");
}
}