黑马程序员技术交流社区

标题: Exercise [打印本页]

作者: 刘邦m    时间: 2019-3-28 16:53
标题: Exercise
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;
    }




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2