求大神解决啊!如果您认为太简单,懒得回答,那就勤快一回吧!快疯了!
本帖最后由 xuechunfeng 于 2013-01-09 10:51:25 编辑
            这是一个“下载”的方法,抛出的异常“文件下载出错: http:\100.0.50.0:8080\download\sample.mp4 (文件名、目录名或卷标语法不正确。)”。目的,是将服务器上的一个mp4文件下载到本地。可是下载下来的视频,却是无效的,大小为(0字节)。可是从正常的项目流程访问进去就会出问题。。求帮忙解决。。谢谢了。。。
为安全起见文中 IP地址为伪造地址,如有雷同,实属巧合。。
抛出错误的地方是在:bis = new BufferedInputStream(new FileInputStream("http://100.0.50.0:8080/download/sample.mp4"));
声明:源文件存放路径绝对没有问题。而且通过给定的那个URL可以正常访问和下载!
       
@Controller
@RequestMapping("/phone")
public class DownloadController {
	
	@RequestMapping(value = "/download")
	public void download(HttpServletRequest request, HttpServletResponse response) {
		
		String filename = "";
		filename = "sample.mp4";
		response.setContentType("application/x-msdownload");
		response.setHeader("Content-Disposition", "attachment; filename=" + filename);
		
		BufferedInputStream bis = null;
		BufferedOutputStream bos = null;
		OutputStream output = null;
		try {
			bis = new BufferedInputStream(new FileInputStream("http://100.0.50.0:8080/download/sample.mp4"));
			output = response.getOutputStream();
			//response.reset();
			bos = new BufferedOutputStream(output);
			byte[] buff = new byte[2048];
			int bytesRead;
			while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
				bos.write(buff, 0, bytesRead);
			}
		} catch (
IOException e) {
			log.error("文件下载出错: " + e.getMessage());
		} finally {
			try {
				if (bos != null)
					bos.close();
				if (bis != null)
					bis.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	private static final Logger log = LoggerFactory.getLogger(DownloadController.class);
}
              
                  java?
                  文件名、目录名或卷标语法不正确
                  视频下载
              
------解决方案--------------------FileInputStream是本地文件。。
------解决方案--------------------new FileInputStream("http://100.0.50.0:8080/download/sample.mp4")
这句我认为系统会在本地找一个名叫http://100.0.50.0:8080/download/sample.mp4的文件,而不会自动上网然后寻找这个。
这是我的一个下载图片的类中的几个方法,楼主看一下吧。
//输入地址url,文件名,输入目录
public static void getfile(String url1, String filename,String dest_folder) throws Exception {
		
		log.info("照片存放目录为:"+dest_folder + "/" + filename);
		File outFile = new File(dest_folder + "/" + filename);
		if (outFile.exists()) {
			return;
		}
		
		OutputStream os = null;
		InputStream is = null;
		try {
			URL url = new URL(url1);
			
			os = new FileOutputStream(outFile);
			is = url.openStream();
			byte[] buff = new byte[1024];
			while (true) {
				int readed = is.read(buff);
				if