java文件下载路径|用java下载指定路径下的文件夹下载内容包含指定文件夹及其包含的文件夹子文件!!

java文件下载路径|用java下载指定路径下的文件夹下载内容包含指定文件夹及其包含的文件夹子文件!!的第1张示图

① java 怎么获取电脑的默认下载路径

不是客户端的东西 不能控制客户端,迅雷或浏览器一类的都是客户端安装的,服务器端的不能随便控制客户端的,客户知道了也不愿意的 那对用户而言 不安全了

② Java提取文件路径

一个file不是有filelist函数吗,可以得到它目录下的所有文件和文件夹名,如果你想再找到它的文件夹下属的文件,再写个迭代吧。一个file,通过isXXX()子函数开判断它是文件还是文件夹

③ java里http服务器如何将文件制成一个下载路径

/***文件下载*/@RequestMapping("/downloadfile")(StringresStr,HttpServletResponseresponse){PrintWriterpw=null;StringBuffersb=newStringBuffer();try{StringfileName="文件名";response.setCharacterEncoding("UTF-8");response.setContentType("application/x-msdownload");response.addHeader("Cache-Control","no-cache,no-store,must-revalidate");response.addHeader("charset","utf-8");response.addHeader("Pragma","no-cache");response.setHeader("Content-Disposition","attachment;filename=""+fileName+"";filename*=utf-8''"+fileName);sb.append(resStr);pw=response.getWriter();pw.write(sb.toString());pw.close();response.flushBuffer();}catch(IOExceptione){logger.info("下载文件出错");e.printStackTrace();if(pw!=null){pw.close();}}finally{if(pw!=null){pw.close();}}}

resStr 字段传写入文件里的内容

④ java文件路径问题

代码无明显逻辑错误注意1、input.in确实存在且内容有效,2.整个代码有没有正确捕获异常。import java.io.File;import java.io.PrintWriter;import java.util.Scanner;public class Test {static public void main(String argv[]){try{File in = new File("c:\\Windows\\System32\\input.in");Scanner s=new Scanner(in);int a = s.nextInt();int b = s.nextInt();File fout = new File("c:\\Windows\\System32\\output.out");PrintWriter out=new PrintWriter(fout);out.println(a+b);out.close();}catch (Exception e){e.printStackTrace();}}} 完整可运行

⑤ java怎么样获取路径下的文件

//根据你的要求修改了一下代码,现在已经能将某文件夹下的所有指定类型文件复制到//指定文件夹下了import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;public class ReadFiles { public static final String FILTER = "xml"; public static final String SRC_DIR = "E:\\StudyData";// 待扫描的文件夹 public static final String DES_DIR = "E:\\testdata";// 复制后的目标文件夹 public static void main(String[] args) { long a = System.currentTimeMillis(); scanDir(SRC_DIR, DES_DIR); System.out.println("共花费时间:"+(System.currentTimeMillis() – a)/1000+"秒"); } public static void scanDir(String srcPath, String desPath) { File dir = new File(srcPath); File[] files = dir.listFiles(); if (files == null) return; for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { scanDir(files[i].getAbsolutePath(), desPath); } else { String strFileName = files[i].getAbsolutePath().toLowerCase(); File(strFileName, desPath + files[i].getName()); } } } public static void File(String srcName, String destName) { if (srcName.endsWith(FILTER)) { System.out.println("正在复制文件 "+srcName+" 至 "+destName); try { BufferedInputStream in = new BufferedInputStream( new FileInputStream(srcName)); BufferedOutputStream out = new BufferedOutputStream( new FileOutputStream(destName)); int i = 0; byte[] buffer = new byte[2048]; while ((i = in.read(buffer)) != -1) { out.write(buffer, 0, i); } out.close(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } } }}

⑥ java读取文件路径

你的头是e://tttt11.PNG不是e://tttt11//1.PNG???如果头是e://tttt11//1.PNG,filepath没有用,去掉。这段这么改:for (i=0; i <= str.length(); i += 2) { if (i == str.length() – 1 || i == str.length() – 2) break; else fileName = str.substring(i); } // System.out.println(filePath); if(ii!=100) fileName = str.substring(i);………..后面不改.如果头是e://tttt11.PNG,那这个和下面的循环规律不一样,大概写下:if(ii==1)filePath=".PNG";把我上面修改后的代码加到else里就行了(用我上面修改后的代码,不然你的尾还是显不出来).

⑦ java 下载服务器端文件,路径怎么写

//得到当前路径下的upload文件夹String strPath = request.getSession().getServletContext().getRealPath("/upload");

⑧ 用java下载指定路径下的文件夹,下载内容包含指定文件夹及其包含的文件夹子文件!!

这个做不了的, 在计算机,你用命令去复制粘贴都需要指定是否递归复制也就是说内,如果你想下载指定的容文件夹,你需要做很多的处理,一个一个文件的下载,然后下载到相对路径中去,还有一种方案就是直接将文件夹打包再下载

⑨ java程序 如何设置下载文件的保存路径

生成一个文件选择窗口,让用户选择路径

未经允许不得转载:山九号 » java文件下载路径|用java下载指定路径下的文件夹下载内容包含指定文件夹及其包含的文件夹子文件!!

赞 (0)