public static void main(String[] args) throws IOException {
StringBuilder imgName=greateName();
FileInputStream fis = new FileInputStream("F:\\JavaTemp\\src\\img.jpg");
FileOutputStream fos = new FileOutputStream("F:\\JavaTemp\\dest\\"+imgName+".jpg");
int len=0;
byte[] bytes = new byte[1024];
while((len=fis.read(bytes)) != -1){
fos.write(bytes, 0, len);
}
fos.flush();
fos.close();
fis.close();
}
private static StringBuilder greateName() {
Random random = new Random();
Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
StringBuilder sb = new StringBuilder();
sb.append(df.format(date)).append(random.nextInt(900)+100);
return sb;
} |
|