java 程序报错数组越界_java字符数组越界

publicstaticStringclassPath=BasicController.class.getClassLoader().getResource("/").getPath();    /**   *图片处理并返回服务器路径存储路径给页面   *

@return

**/

@RequestMapping("/toImg.do")

@ResponseBody

publicResulttoImg(StringBase64,HttpServletRequestreq,HttpServletResponseres){

//ImageBase64base=newImageBase64();

//时间戳图片名

Resultresult=newResult();

Stringtimename=newSimpleDateFormat("yyyyMMddHHmmss").format(newDate());

StringrootPath;

Stringfile;

if("\\".equals(File.separator)){

//绝对路径

//Windows

file=req.getSession().getServletContext().getRealPath("\\")+"upload\\image\\"+timename+".jpeg";

Stringlastpath=file.split(":")[1];

file=file.split(":")[0]+":\\"+lastpath;

//适用通用判断类型,以上舍弃

rootPath=classPath.substring(1,classPath.indexOf("/WEB-INF/classes"));

rootPath=rootPath.replace("/","\\");

file=rootPath+"/upload/image/"+timename+".jpeg";

}else{

//Linux

rootPath=classPath.substring(0,classPath.indexOf("/WEB-INF/classes"));

rootPath=rootPath.replace("\\","/");

file=rootPath+"/upload/image/"+timename+".jpeg";

}

/***

已解决,谢谢各位,以上是实际代码

*/判断操作系统,只有Windows才有盘符的概念。

只有windows的盘符才有 :这个字符。

“\”反斜线好像只有windows上才支持,建议全部使用“/”,这个应该是多平台都支持的java的url类里应该有seperator常量可以用

应该是\反斜线的问题,使用/吧(Win和Linux都支持)。以后所有的路径都用/表示就对了

File.separator分隔符用这个有系统差异性我擦

系统差异吧,但java却又是跨平台的。

把错误debug下,或log下,应该可以找到原因。不存在:所以分割失败,数组1就索引不到了,越界

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值