Path 1 « directory « Java I/O Q&A





1. What is the best way to work with file paths in java?    stackoverflow.com

I believe it's the File class but I heard that is very expensive in memory. Is there a better way to work with file paths?

2. How to Check Path is existing or not in java?    stackoverflow.com

I have a java program which take path as argument. I want to check whether given path is existing or not before doing other validation. Eg: If i give a path ...

3. Does Java have a path joining method?    stackoverflow.com

Exact Duplicate:

combine paths in java I would like to know if there is such a method in Java. Take this snippet as example :
// this will output a/b
System.out.println(path_join("a","b"));
// a/b 
System.out.println(path_join("a","/b");

4. Checking for a Valid Path when Uploading a File Using commons-fileupload    stackoverflow.com

I'm working with some code that uploads an image from a form and stores it on our server. In Internet Explorer the user can enter a path manually, and I wonder ...

5. How do I store files or file paths in a java application?    stackoverflow.com

I apologize if this is a really beginner question, but I have not worked with Java in several years. In my application, I need to keep up with a list of ...

6. Storing a file in the user's directory in cross-platform Java    stackoverflow.com

I have a Java application that runs on Mac and Windows, directly off a CD/DVD with no installation. Now, I need to store a file containing per-user data (think favourites ...

7. How to specify filepath in java?    stackoverflow.com

I have created a java application for "Debian Linux." Now I want that that application reads a file placed in the directory where the jar file of that application is specified. ...

8. Is there a Java utility which will convert a String path to use the correct File separator char?    stackoverflow.com

I have developed a number of classes which manipulate files in Java. I am working on a Linux box, and have been blissfully typing new File("path/to/some/file");. When it came time to ...

9. Where will be create a new file in java, when path is not given?    stackoverflow.com

In java,

File f;
f = new File("myfile.txt");
if (!f.exists()) 
{
    f.createNewFile();
}
when excute the above code,which path is assigned in default, while specific path is not given?





10. File.separator vs Slash in Paths    stackoverflow.com

What is the difference between using File.separator and a normal / in a Java Path-String? In contrast to double backslash \\ platform independence seems not to be the reason, since both versions ...

11. How do i get file path of my file in java enterprise application?    stackoverflow.com

I created java enterprise application and it consists of ejb module and web application. I have plain old xml file in source packages folder in package "common" in my ejb module. ...

12. File library that help creating paths    stackoverflow.com

I'm looking for a file utilities library that help creating paths, i.e. if I want to create a file in "a/b/c/x/y/z", it will check if each directory exists and creates it ...

13. How do I specifiy a path to a file in Java?    stackoverflow.com

Ok this is a homework questions, but I cannot find the answer anywhere, not even in the book. Path to Files If the user wants to specify a path for a file, ...

14. Where to store global variables like file paths in java?    stackoverflow.com

In my application I use some icons. Where should I store the path of the directory containing those icons ? The icons are used in different classes so it doesn't really ...

15. Java Filepath Question    stackoverflow.com

I am trying to finish a java program that uploads a file from a client machine to a webserver. The java program is executed with a bat script. I need to ...

16. Getting file path in java    stackoverflow.com

Is there a way for java program to determine its location in the file system?





17. Get file full path in java    stackoverflow.com

When I pass File file to a method I'm trying to get its full path like file.getAbsolutePath(); I always get the same result no matter which one I use either absolute ...

18. how to set the path in this file    stackoverflow.com

im using Sphinx and i have configured my gammar model path which is build\class\FYP but in my configuration file i just wanted to put FYP in the configuration component as follow

 <component name="jsgfGrammar" ...

19. Platform independent paths in Java    stackoverflow.com

I know the relative path of a file, and want to be able to handle it as a File object on both Linux and Windows. What is the best way to ...

20. how to pass jasper file path to subreport of subreport    stackoverflow.com

I am using iReport tool in conjunction with JasperReports 1.3.4. I have a master report, which contain two subreports. One of these subreports has an embedded subreport. All of the .jasper files ...

21. create path from several file objects or just one    stackoverflow.com

I am working on different platforms (Solaris/Windows). I need to create a File object which contains several path elements. The question is: is it better to create the final File object ...

22. doubt in file path    stackoverflow.com

i tried a program comparing C:\Program Files and C://Program Files i checked with compareTo()==0 it comes they are equal. But i doubt if there is any difference between //&\ Is ...

23. How to get correct path of configuration file?    stackoverflow.com

I created a Java project that contains three configuration file

  • log4j.XML
  • QueueConfig.xml
  • rabbitmq.properties
I put these three files into a resource folder. Then I created a jar file of my project. This jar file is added ...

24. Crossplatform file path building and representation    stackoverflow.com

I am in a refactoring stage for a project I am working on and would like to make some improvements to how I build and represent file system paths. What things ...

25. how to check if a given path is possible child of another path    stackoverflow.com

I am trying to find if given path is possible child of another path using java. Both path may not exist. Say c:\Program Files\My Company\test\My App is a possible child of c:\Program ...

26. Java normalize file path for external execution    stackoverflow.com

I have this code:

StringBuilder command = new StringBuilder("ffmpeg -ac 1 -i ");
command.append(videoFile.getPath());
command.append(" ");
command.append(audioFile.getPath());
Process proc = Runtime.getRuntime().exec(command.toString());
The problem is when the file (videoFile | audioFile) have a space character in their path, ...

27. Create File in any Path on Mobile Device    stackoverflow.com

I want to create a file on mobile phone and the file path is determined by the user. In my mobile phone (Nokia) the list is that: Phone Memory:/ , C:/ , ...

28. in java my file paths with included spaces show up as %20 and i'm not sure why    stackoverflow.com

I have a photo selection model, but for some reason whenever I call the path of the images, the space in the path is converted to it's HTML code and I'm ...

29. Java - Adding directories to PATH?    stackoverflow.com

I'm going through the Java EE 6 Tutorials and on page 68 under SDK Installation Tips, it says: "After you install the GlassFish Server, add the following directories to your ...

30. How to get the complete real file path for "../../dir/file.ext" in java?    stackoverflow.com

I there a way in the java.io package to convert a relative path containing "../" to an absolute path? My goal is to remove the "../" part of the path because

 ...

31. how to get free space of unc path in java code?    stackoverflow.com

I want to know the free space on UNC path(network path like \server\foldername) using java. I found a sample to know the free space on local drive:

import java.io.File;  

public class GetFreeSpace ...

32. Check if file path is correct without checking if file exists    stackoverflow.com

I am working on an application installer. The user has to provide a file / directory path that will later be created by the application. I need to check if that ...

33. How to check if a path points to an existing file with Java 7's new File API?    stackoverflow.com

The old, more or less deprecated java.io.File API had a method exists which returned true if the File pointed to an existing one in the file system, but I couldn't find ...

34. How to get complete path of a directory by giving a subset of its path in Java?    stackoverflow.com

E.g If I provide \abc\xyz , is it possible to get <drivename>:\somefolder\abc\xyz ?

35. how to handle different language in file/folder path    stackoverflow.com

I have written an application which takes folder path and perform some operation. But if folder path contains characters of language other than English then it is not working. It only ...

36. Java file path in web project    stackoverflow.com

I need to access resource files in my web project from a class. The problem is that the paths while developing are different from deployed paths. For example, if I want ...

37. How to handle ~ in file paths    stackoverflow.com

Writing a simple cmd line java utility. I would like the user to be able to pass in a file path relative to their home directory using the ~ operator. So ...

38. Can I compose two file paths without needing their toString() methods?    stackoverflow.com

Imagine I have a 'base' path object, denoting a directory, and a 'relative' path object denoting some file within the base. I would expect that code to look somewhat like

AbsolutePath base = ...

39. Generate Random File Paths Java    stackoverflow.com

Is there some way to randomly generate an arbitrary file path in Java? What I've been thinking is that perhaps I could either pick one out of a pre-selected array, but that ...

40. canonical file path in java - optimization problem?    stackoverflow.com

My file structure has a symbolic link to a directory /home/me/myDir -> /some/other/dir. This link gets updated by another process and the notifies my process. Upon notification I attempt to get ...

41. How to escape the backslashes and the automatically generated escape character in file path in java    stackoverflow.com

I have very small and simple problem but I am not getting solutions on it. Actually I am getting a CSV file path using file chooser. I am entering the data in this ...

42. Best practices to work with file paths in Java    stackoverflow.com

I m trying to load properties file to create a configuration. namely foo.properties. What the best place to store this config file. Within the package where i will use initialize the using ...

43. how to set path for this created file in an argument    stackoverflow.com

How do I set path for this created file? The user should specify the path in his arguments. Currently this code is able to create a file. The user needs to ...

44. Java - is one file path part of another?    stackoverflow.com

I am wondering if there is a quick simple way to check whether a file path comes under another path. For example, given C:\Fruit\Apple\Core, I want to test it against a ...

45. How to get all file paths while using html "file" input with multiple attribute    stackoverflow.com

I am developing a web page in which I have to upload multiple files on a single browse. I am using html <input id="filelist" type="file" multiple=multiple> This enables the multiple file selection and also ...

46. Java7 / Path / File / get a unique ID like an Inode of a file    stackoverflow.com

How do I get a unique ID from a Path or File instance which must have an Inode or another unique ID in a "non Linux/Unix" filesystem? Can't find anything in ...

47. Getting a file path    coderanch.com

48. How to override a file in another path?    coderanch.com

this is the program: File sourceFile1 = new File(ls_tempImage1); File destFile1 = new File(destFileUrl1); fileLength1 = sourceFile1.length(); FileInputStream fis1 =null; FileOutputStream fos1 =null ; try { fis1 = new FileInputStream(sourceFile1); fos1 = new FileOutputStream(destFile1.getAbsolutePath(),false); } catch(FileNotFoundException fnfe) {} finally { try { for (i=1;i<=fileLength1;i++){ fos1.write(fis1.read()); } fis1.close(); fos1.close(); } catch(IOException ioe) { System.err.println("File Closing error: " + ioe); } } and ...

49. paths    coderanch.com

I want to read through a flat txt file that I know will always be in the same root directory as my jar file on every machine. However, I don't know what this root directory will be on each machine so how do I make my code flexible enough to be installed on any machine? I have this situation : C:\root\myFlatFile.txt ...

50. How to get path where application is installed?    coderanch.com

Hi, What I need to do is write a file to a relative directory to where my Java application is going to be installed. Where it will be installed can vary of course. So when I create my file like new File(parentName, child); I know my child path and name but not how to get the parent. Also, this is cross ...

51. File objects as a path    coderanch.com

Hi, all. I've written an app that finds data in a file and renames the same file based on the data found. It's self contained. I'm trying to make some of the code reusable but am having trouble getting the file objects passed between the classes. It finds the file list but can't find the file once I pass the BufferedReader ...

52. Input files in program path    coderanch.com

I'm not even sure how to ask this.. I'm writing a java application that stores its data in a text file. Whenever the user changes (adds/deletes/modifies) data, the file needs to be re-written. The program needs to read the input file on startup. I want the program to "know" that it needs to look in the same directory that the program ...

53. file path    coderanch.com

You don't have to create the file because File file = new File("blah"); just gives you a handle to a - potentially nonexistent - file. You can use 'file.exists()' to determine if it's a real file. if i had to look for a MS app, i would (a) first take a stab a finding it in it's default install dir or ...

54. FilePath on SOLARIS ?    coderanch.com

Hi, I have a strange problem ..... i have a File object File f=new File("./"); f.getAbsolutePath(); Gives me the path of the current directory ..... in windows Now if i try to print the absolute path in SOLARIS it just prints ./: .....i dont understand why .... if am i doing any thing wrong .... how do i get the present ...

55. path trouble    coderanch.com

I have a problem running a jar file I made in another computer, but it works in th original computer, this computer is the same platform my developing computer uses. in the jar file I included a folder called Resources which contains images. when I look in the jar file the path is Resources/image.gif in my program in the jar file ...

56. File path \\ //    coderanch.com

Backslash is the correct file separator for Windows, but forward slash is accepted in many situations. Doubling the backslash is necessary because backslash is an escape character in Java string literals. Doubling the forward slash is just wrong, and I am surprised if it works. Note that hard-coding such a path makes your code specific to Windows, and specific to a ...

57. get parent directory path    coderanch.com

Ok, I have a file created as new File ("full path") I want to display the full path of parent directory that the file is in. I do a createdFile.getParent() but I get a null. What is teh quickest way to display the path of the parent directory without tokenizing the createdFile.getAbsolutePath() ??? Thanks for your help.

58. deleteMethod(filePath) WebDAV    coderanch.com

I am using Jakarta Slide API for managing documents. I am using deleteMethod(filePath) to delete a file on my web URL. This is returning a boolean true. So accordingly if i check the url of that particular file it should not turn up as it is deleted. But it does turn up. It doesnt give File Not Found Exception. Is it ...

60. class.getResource(path) not working ??    coderanch.com

61. Recycle bin path    coderanch.com

62. How to escape whitespace in file path    coderanch.com

Hi EveryBody I am reading a file which consist of space in its name. The location of the file is C:/Documents and Settings/venkatesh/XMLtest/ListPageDisplayPropertiesMapping.xml The exception that i am getting is attached at the end of this message for reference. Simplest thing that can be done is i can change the directory name so that there are no spaces. However this file ...

63. path to load a file    coderanch.com

64. Physical Path of a file    coderanch.com

65. directory path    coderanch.com

Hello, Both the methods yo have specified does not return the ditectory pathe. The getPathInfo() Returns any extra path information associated with the URL the client sent when it made this request. The extra path information follows the servlet path but precedes the query string and will start with a "/" character. This method returns null if there was no extra ...

66. Path to config file    coderanch.com

Hi, Sorry for the newbie question, I'm sure the answer is obvious but I can't find it... I have a config.xml file in WEB-INF (next to web.xml and struts-config.xml) and I need to pass this files location to a commons digester program (reads in xml files). The digester program needs the full path and file name. If i put the file ...

67. Very argent file path    coderanch.com

68. file path in web container    coderanch.com

69. Openning a data file using relational path    coderanch.com

Hello I am trying to open a data file ( a header and footer and sometimes other files ) using a function I have written: Call sample: utils.InsertFile("header.inc"); public static String InsertFile(String FileName) { String str=""; try{ BufferedReader br = new BufferedReader (new InputStreamReader (new FileInputStream (FileName), "UTF-8")); String line; while ((line=br.readLine()) != null) str +=line; br.close(); } catch(IOException x){str+="Error in ...

70. Using Directory Path as Parameters?    coderanch.com

Originally posted by Rob Mech: Yeah, guess I could do that but then why did I bother posting a question on the friendly site for greenhorns. Seems pointless to ask a question to be told find it yourself. There is nothing unfriendly about teaching a man how to fish. JavaRanch is primarily a learing site -- not someplace to just get ...

71. The abstract path of IO    coderanch.com

Hi YanJun, Have you try using the proper File("../../something/file.txt")? It works for me perfectly. Anyway, this will stop working as soon as you package your files in a jar file. You can access the files regardless on if they are in filesystem or in jar using: Class.getResourceAsStream("path/to/resource"); but your abc.txt would have to be in the same directory as the class ...

72. Xloggc:filepath - whitespace problem in directories    coderanch.com

Hi all i am working on client side applets that basically updates client plugin jre params when we run the applet. this is to enable GC information where all our applets run in windows. we are maintaining all our client side logs in 'C:\Documents and Settings\\Application Data\ClientLogs\' so we decided to log Verbose gc information also in the above path.default path ...

73. Filepath Help    coderanch.com

My picture panel gets the image from the same folder that stores my class files in NetBeans but I have a folder called Actors and would like the filepath to be directed there. I have tried to use ./Actors/file.jpg without any succes. public class Picture extends JPanel { Image img; public Picture(String file) { img = new ImageIcon(this.getClass().getResource(file + ".jpg")).getImage(); this.setBorder(BorderFactory.createLineBorder(DARK_BLU, ...

74. getting path of a file    coderanch.com

Have you looked in the java.io.File class in the API specification? You can put the name in as the argument in the contructor, and there are two methods which get the path. Have you tried that? Does it work? Do you want canonical path or absolute? If you aren't sure, try absolute first and see whether it works. CR

75. file path    coderanch.com

76. Get the path to the install directory    coderanch.com

77. How to override a file in another path?    coderanch.com

78. Path to File    coderanch.com

79. Getting the users directory path    coderanch.com

80. specifying paths to create file    coderanch.com

While we're on the topics... Note that putting two \ characters together is referred to as character "escaping". The \ character is the escape character, which is used in combination with other characters to specify various special sequences. Section 3.10.6 of the JLS describes the various escape sequences. As Ernest already pointed out, to specify a \ character, it must be ...

81. how to get file path    coderanch.com

82. How to include full file path in io?    coderanch.com

83. How to instantiate a file from a realtive path?    coderanch.com

Hello all: I want to instantiat a file from the class path. File file = new File("c:// .../.../.../myJar.jar"); I don't want to use the absolute file path. The jar file I am trying to instantiate is in the project class path. I tried "../myJar.jar" and it didn't work. Any help is greatly appreciated.

84. path to load a file    coderanch.com

85. Problem with the path inside a jar-file    coderanch.com

hello everybody, actually i am coding a small tool. i am using ide eclipse. there i have built a project with a few classes and in the root of the project there is folder containing several .txt files. if i read them with my application in eclipse, there is no problem. but then i built a jar file (using fat jar ...

86. Cross Platform File Path    coderanch.com

Hello all, I am currently tasked with writing a service method that abstracts away some of the details about how a file that is uploaded to our web application is stored. The goal here is to allow us to upgrade to a CMS in the future and not have to change a great deal of code. I admittedly have very little ...

87. How to get the file path right?    coderanch.com

88. Where should file path be?    coderanch.com

I need to load a text file for my program. It only loads when its the absolute path, like C:\\file.txt. I want to make it so that it loads relative paths, so typing file.txt would load as long as its in the same directory as the program. I'm using Netbeans IDE and I tried putting file.txt by the classes and by ...

90. get application filepath    coderanch.com

91. file path    coderanch.com

Hi, I have a question about file location. when I give physical location (for example c:\test\file.txt) for my file path on my local machine. The file can be found and read. My question is: does it work in DEV or PROD environment? if not, what is the correct path I should give? Thanks

92. File loading and paths when running in an IDE, and outside an IDE.    coderanch.com

Hello all. My first post here although I first came upon your friendly forums many moons ago. I'm an experienced developer, but not with Java. And there is something that has really been eating my brain of late that I feel I need to come to terms with. And that is file paths in Java. I have some questions. 1) Reading ...

93. file path retention    coderanch.com

I'm creating a monthly planner program in java swing. I'm planning to use a file to serialize the objects. Right now, I've hard coded the file path in the program. What I want to do later is to ask the user to provide a file path and use that file path for serialization. But I don't know how to retain or ...

94. File constructor puts a forward slash in the constructed path    coderanch.com

The java application with the following segment of code deployed on Tomcat running on Open VMS OS. The first line of code constucts pathname for the file inhous.properties. It blows up because it puts forward slash as shown in the System.out statement (second line of code) File propFile = new File("Disk_5:[apache.jakarta.tomcat.conf]" , "inhouse.properties"); System.out.println("propFile = " + propFile); System.out = Disk_5:[apache.jakarta.tomcat.conf]/inhouse.properties ...

95. file path is greater than 100 characters    coderanch.com

Hi All i have this issue in my project running in production ":file path is greater than 100 character". any fix will be appreciated greatly .... By the way i have seen your fix in topic "How to make a Tar in java" but have not tried/tested it. Actually my project is lookin for new tar utility due to this above ...

96. Check if a path is a directory or a file    coderanch.com

Hey, I want to create a FileOutputStream from a String representation of a file on the disk. Now, if the file does not exist, I want to create it, like so: if (!resourceFile.exists()) { resourceFile.mkdirs(); resourceFile.createNewFile(); } return new FileOutputStream(resourceFile, append); Also, the missing directory structure will be created. My problem now is that when the caller passes a directory rather ...

97. How to point PATH envirnoment to /bin directory?    coderanch.com

The path environment variable is used by the console do determine which methods can be called. Usually it's the executes that are in the current directory and which are on the path. On windows you can edit your environment variables in your control panel under user accounts. Just append ";C:\pathToJava\bin" to it without the "". I'm sure that someone else can ...

98. Browse- need full file path    coderanch.com

Actually i am able to upload thinking the source location remains the same and going ahead to upload the file, and more over the server on to which i am uploading has a webdav application running on it, so it handles the incoming file whether application/x-rar application/pdf .. .. etc is it exactly what you are talking about or any other. ...

100. Create new file with spaces in file path    coderanch.com

Trick is to go over URI, that is handled the same in all operating system. public static void main(String[] args) { String output = "c:/abc def/a.txt"; try { URI outputURI = new URI(("file:///"+ output.replaceAll(" ", "%20"))); File outputFile = new File(outputURI); if (!outputFile.exists()) { createParents(outputFile); outputFile.createNewFile(); } } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException ...