Java file path

xiaoxiao2021-04-03  275

The previous XML parses mentioned the file reading. The first step in this operation is to correctly represent the path to the file. So simply talk about the file path settings of the two. First, you can view the current directory with the following method, your file path can be used as: system.getprintln (System.GetProperty ("User.dir")); if you use this method to see you The JSP page can be found that it is very strange, actually it is a JSP engine path. So when you use new file (String Path), if you use a relative path, you have a relatively real current path, not any path you want to of course. Of course, the "absolute path" is generally not wrong for this method. Just this, the flexibility of the program is limited. Below is an example of an absolute path: string xmlpath = "d: //publicfiles//wci//navigation.xml"; Part 2FileStream file = this.getClass (). GetClassLoader (). GetResourceSstream (String Xmlpath); this is a bit complex I know much more, let's talk about it now, I will add it now! System.out.println (this.getClass (). GetClassLoader (). GetResource ("/"). GetPath ()); you can see the root path relative to "/". FileStream filestream = this.getClass (). GetClassLoader (). GetResourceAsStream (); FilePath); here can only use relative paths, at least I don't know how to use absolute paths: String filepath = "/../../Resources/xml/navigation.xml"; // Expression rules are the same as Linux. System.out.println (this.getClass (). GetClassLoader (). Getresource ("."). GetPath ()); system.out.println (this.getClass (). GetClassLoader (). GetResource ("/") .getPath ()); System.out.println (this.getclass (). getClassLoader (). getResource (""). getPath ()); system.out.println (this.getClass (). getClassLoader (). getResource (".."). getPath ()); I believe that you should know where to place your own files, what kind of statement can be found. Today, when writing a written JSP, I encountered the problem of the file path above, and I believe there is a lot of mistakes. I hope you can ask and correct it, I am here!

转载请注明原文地址:https://www.9cbs.com/read-131461.html

New Post(0)