获取文件绝对路径|javaweb中怎么获取文件的绝对路径

获取文件绝对路径|javaweb中怎么获取文件的绝对路径的第1张示图

⑴ 怎样获得文件夹中所有文件的绝对路径列表

你点击一个文件后,在页面上方的地址栏里,就是这个文件的绝对路径,用右键点几这个地址,复制后在任何一个文件中粘贴就可以了。需要用的话,只须把这个地址复制回去。

⑵ 如何获取上传文件的绝对路径

参考例子如下,相关注释已经在代码中写明;#region 文件上传/// <summary> /// 上传文件(自动分割) /// </summary> /// <param name="filePath">待上传的文件全路径名称(@"E:\FTP\ftproot\20070228DQCK.zip")</param> /// <param name="hostURL">服务器的地址</param> /// <param name="byteCount">分割的字节大小</param> /// <param name="userID">主机用户ID</param> /// <param name="cruuent">当前字节指针</param> /// <returns>成功返回"";失败则返回错误信息</returns>public string UpLoadFile(string filePath, string hostURL, int byteCount, string userID, long cruuent){ string tmpURL = hostURL; byteCount = byteCount * 1024; System.Net.WebClient WebClientObj = new System.Net.WebClient(); FileStream fStream = new FileStream(filePath, FileMode.Open, FileAccess.Read); BinaryReader bReader = new BinaryReader(fStream); long length = fStream.Length; string sMsg = "版式上传成功"; string fileName = filePath.Substring(filePath.LastIndexOf('\\') + 1); try { #region 续传处理 byte[] data; if (cruuent > 0) { fStream.Seek(cruuent, SeekOrigin.Current); } #endregion #region 分割文件上传 for (;cruuent <= length; cruuent = cruuent + byteCount) { if (cruuent + byteCount > length) { data = new byte[Convert.ToInt64((length – cruuent))]; bReader.Read(data, 0, Convert.ToInt32((length – cruuent))); } else { data = new byte[byteCount]; bReader.Read(data, 0, byteCount); } try { hostURL = tmpURL + "&action=upload" + "&filename=" + fileName + "&userid=" + userID + "&npos=" + cruuent.ToString(); //hostURL = tmpURL + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; byte[] byRemoteInfo = WebClientObj.UploadData(hostURL, "POST", data); string sRemoteInfo = System.Text.Encoding.Default.GetString(byRemoteInfo); // 获取返回信息 if (sRemoteInfo.Trim() != "") { sMsg = sRemoteInfo; break; } } catch (Exception ex) { sMsg = ex.ToString(); break; } } #endregion } catch (Exception ex) { sMsg = sMsg + ex.ToString(); } try { bReader.Close(); fStream.Close(); } catch (Exception exMsg) { sMsg = exMsg.ToString(); } GC.Collect(); return sMsg;}#endregion

⑶ javaweb中怎么获取文件的绝对路径

在jsp和class文件中调用的相对路径不同。 在jsp里,根目录是WebRoot 在class文件中,根目录是WebRoot/WEB-INF/classes 当然你也可以用System.getProperty("user.dir")获取你工程的绝对路径。另:在Jsp,Servlet,Java中详细获得路径的方法!1.jsp中取得路径: 以工程名为TEST为例: (1)得到包含工程名的当前页面全路径:request.getRequestURI() 结果:/TEST/test.jsp (2)得到工程名:request.getContextPath() 结果:/TEST (3)得到当前页面所在目录下全名称:request.getServletPath() 结果:如果页面在jsp目录下 /TEST/jsp/test.jsp (4)得到页面所在服务器的全路径:application.getRealPath("页面.jsp") 结果:D:/resin/webapps/TEST/test.jsp (5)得到页面所在服务器的绝对路径:absPath=new java.io.File(application.getRealPath(request.getRequestURI())).getParent();结果:D:/resin/webapps/TEST 2.在类中取得路径: (1)类的绝对路径:String u=Class.class.getClass().getResource("/").getPath() 结果:/D:/TEST/WebRoot/WEB-INF/classes/pack/ (2)得到工程的路径:System.getProperty("user.dir") 结果:D:/TEST 3.在Servlet中取得路径: (1)得到工程目录:request.getSession().getServletContext().getRealPath("") 参数可具体到包名。 结果:E:/Tomcat/webapps/TEST (2)得到IE地址栏地址:request.getRequestURL() (3)得到相对地址:request.getRequestURI() 结果:/TEST/test

⑷ 在Java中如何取得文件的绝对路径

File类中的getAbsolutePath方法可以获得绝对路径。

⑸ linux shell脚本中如何获取文件的绝对路径readlink可以么

传给函数的路径是/root/file,如果这是函数的第一个参数,那么函数中可以用 $1 获取。得到文件版名file1和file2后,echo "$1/file1" 就输权出/root/file/file1,echo "$1/file2" 输出/root/file/file2。

⑹ 怎么获取assets文件夹下的绝对路径

apk安装以后放在/data/app/**.apk,以apk形式存在,asset/res和apk在一起,并不会解压到/data/data/YourApp目录下去,所以你无法直接获取到assets的绝对路径

⑺ C#怎么获取当前文件的绝对路径

不知道你要的是不是这个 AppDomain.CurrentDomain.BaseDirectory 获取当前应用程序域的基目录

⑻ 如何获取文件的绝对路径

String path = context.getFilesDir().getPath();

⑼ C# 获取文件夹的绝对路径

这个文件夹 不一定会生成到最终发布目录,这个要看里面的文件是什么性质,是不是内容文件并复制到输出目录。1. System.Diagnostics.Process.GetCurrentProcess().MainMole.FileName获取模块的完整路径。2. System.Environment.CurrentDirectory获取和设置当前目录(该进程从中启动的目录)的完全限定目录。3. System.IO.Directory.GetCurrentDirectory()获取应用程序的当前工作目录。这个不一定是程序从中启动的目录啊,有可能程序放在C:\www里,这个函数有可能返回C:\Documents and Settings\ZYB\,或者C:\Program Files\Adobe\,有时不一定返回什么东东,我也搞不懂了。(注:此方法取值不固定,随着OpenFileDialog、SaveFileDialog等对象所确定的目录而改变)4. System.AppDomain.CurrentDomain.BaseDirectory获取程序的基目录。5. System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase获取和设置包括该应用程序的目录的名称。6. System.Windows.Forms.Application.StartupPath获取启动了应用程序的可执行文件的路径。效果和2、5一样。只是5返回的字符串后面多了一个"\"而已7. System.Windows.Forms.Application.ExecutablePath获取启动了应用程序的可执行文件的路径及文件名,效果和1一样。

⑽ linux下 Java如何获取文件的绝对路径

需要使用路径时,用下面的方法取得项目根目录的绝对路径(Tools为方法类)public static String getRootPath() {String classPath = Tools.class.getClassLoader().getResource("/").getPath();String rootPath = "";//windows下if("\\".equals(File.separator)){rootPath = classPath.substring(1,classPath.indexOf("/WEB-INF/classes"));rootPath = rootPath.replace("/", "\\");}//linux下if("/".equals(File.separator)){rootPath = classPath.substring(0,classPath.indexOf("/WEB-INF/classes"));rootPath = rootPath.replace("\\", "/");}return rootPath;}

未经允许不得转载:山九号 » 获取文件绝对路径|javaweb中怎么获取文件的绝对路径

赞 (0)