文件上传方式

1.文件的上传(sqlite文本数据库)

页面:<tr height="30" bgcolor="#F1F1F1">
          <td width="128" class="tb11">图片</td>
          <td class="tb12"><input type="file" name="img">
            <span id="note-devicename">&nbsp;</span></td>
        </tr>

后台中操作

if (img == null) {

            throw new RuntimeException("请上传图片!");//判断数据是否上传的值
        }
        if (img.indexOf(".") == -1) {
            throw new RuntimeException("您上传的文件无法获得后缀名!");//判断数据上传的值中是否拥有
        }
        String temp = img.substring(img.indexOf(".") + 1, img.length());//获取文件的后缀名
        if (!temp.equals("bmp") && !temp.equals("dib") && !temp.equals("gif")//判断后缀名的格式
                && !temp.equals("jpe") && !temp.equals("jpeg")
                && !temp.equals("jpg") && !temp.equals("png")
                && !temp.equals("ico")) {
            throw new RuntimeException(
                    "您上传的图片格式不符合要求,请确定上传的是bmp/gif/jpg/ico/png/jpeg格式!");
        }
        File file = new File(getFiles().get("img").toString());//获取文件
        if (!file.exists()) {
            throw new RuntimeException("请上传图片!");
        }
        String newImg = "img/" + UUID.randomUUID();//给其一个随机的名称
        FileUtils.copyFile(file, new File(Http.baseUrl + newImg));//public class Http extends NanoHTTPD {public static String baseUrl = "sdcard/web/";文件的copy的文件
        area.setImg(newImg);//将文件的新名称导入到数据库中
        AreaControl.areaDao.insert(area);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值