Remove hardcoded file path from java program -


I have created a simple Java program in which I am creating a text file and reading the data written in it. The problem is that I do not want to hardcode the path of the file because I have created an installer package for my program after the development of the application that allows users to install it on that system. Now the problem can be installed anywhere in the same way as a user (i.e. in C, D or E Drive) and in those cases I get the filenoutfound exception exception.

My code - this is the code that I am using to create and write some text in the text file.

  Forforter file = new flumerwriter ("e: \\ TextFile.txt", is true); BufferedWriter Author = New BufferedWriter (file); Author.write (input); Write.newLine (); Write.close ();  

This is the code that I am using to read text from the text file.

  Flemmer reader = new file reader ("e: \\ TextFile text"); Buffer Data = New Buffettder (Read);  

I have another file for which I hardcode the path of the file.

  System.setProperty ("webdriver.chrome.driver", "D: \\ new folder \\ chromedriver.exe");  

As you can see in all your code, I use the path ("E: \ TextFile.txt", "E: \ TextFile.txt" and "D: \ New Folder \ Chromeerier.program file "). Is there any way to remove them in Java? I went through similar questions but was not able to locate the location of the file.

I made changes according to sugis and it worked for me -

  // This gives me the path to the application where it has the string path = new file ("") installed. GetAbsolutePath ();  

Then I add the file name along the path to get the file.

FileReader = New FileReader (path + "\\ TextFile.txt"); I read the fileReader here to read the file name in the path here; // Here I am adding the file name to the path in the file to write FileWriter file = New FileWriter (path + "\\ TextFile.txt", true);

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -