jsp上传文件怎么获得文件在电脑中的绝对路径
请导入考勤文件:<inputtype="file"name="workfile"id="work"/>inputtype="button"value="确定"/>,我想点...
请导入考勤文件:<input type="file" name="workfile" id="work"/> input type="button" value="确定" />,我想点确定后将文件导入到mysql中,java中的代码
public List<Work> readWork(String path) throws DAOException {
List<Work> work = new ArrayList<Work>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
File file = new File(path);
FileInputStream fis;
try {
fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis, "utf-8");
BufferedReader br = new BufferedReader(isr);
String str = null;
while ((str = br.readLine()) != null) {
String array[] = str.split(",");
Work w = new Work();
w.setInnerCode(array[0]);
w.setWorkDate(new java.sql.Date(sdf.parse(array[1]).getTime()));
w.setWorkLong(Double.parseDouble(array[2]));
work.add(w);
return work;
}
应该怎么写呢?急求! 展开
public List<Work> readWork(String path) throws DAOException {
List<Work> work = new ArrayList<Work>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
File file = new File(path);
FileInputStream fis;
try {
fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis, "utf-8");
BufferedReader br = new BufferedReader(isr);
String str = null;
while ((str = br.readLine()) != null) {
String array[] = str.split(",");
Work w = new Work();
w.setInnerCode(array[0]);
w.setWorkDate(new java.sql.Date(sdf.parse(array[1]).getTime()));
w.setWorkLong(Double.parseDouble(array[2]));
work.add(w);
return work;
}
应该怎么写呢?急求! 展开
1个回答
展开全部
因为浏览器安全保护,你直接通过浏览器获取文件的绝对地址是获取不到的,你不是已经通过input标签获取文件了么
File workfile = (File)request.getAttribute("workfile");
fis = new FileinputStream(workfile)就可以读到了
File workfile = (File)request.getAttribute("workfile");
fis = new FileinputStream(workfile)就可以读到了
更多追问追答
追问
还是不太清楚,我的那个java代码中应该怎么给path赋值呢?
追答
你用input标签指定类型是file了,传到后台就是一个File类型,直接获取就好了,为什么非要用路径new一个出来呢?直接
File file = (File)request.getAttribute("workfile");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询