Where to find WebDriverManager "~/.cache/selenium" absolute path? - java

I'm using WebDriverManager via io.github.bonigarcia maven package. Based on documentation the following line of code places the latest chromedriver file in ~/.cache/selenium...
WebDriverManager.chromedriver().setup();
My question: What should be the absolute path for that relative path "~/.cache/selenium"?
Thank you in advance!

~ here is your user working folder.
For example on Windows based system the file will be located in:
C:\Users\yourName\.cache\selenium
folder.
So, if my user folder on my computer is called Prophet it will be
C:\Users\Prophet\.cache\selenium

Related

Have WebDriverManager Download to Specific Directory

I understand that the following line of code places the latest chromedriver file in ~/.cache/selenium...
WebDriverManager.chromedriver().setup();
My question: Is there a way to configure this to download the file to a specific directory?
As an example, say I have a directory named "MyChromeDriver". I would like WebDriverManager to place the chromedriver file inside "MyChromeDriver" without all the extra sub-directories.
Thank you in advance!
Invoke WebDriverManager as follows:
WebDriverManager.chromedriver().cachePath("MyChromeDriver").avoidOutputTree().setup();

Reference a Text File with relative path in Java with the IntelliJ IDEA

I have a program that reads numbers from a .txt file. My problem is where to place this file, or how to reference it with a relative path to make this file accessible without using the absolute path.
When you try to open a file, it takes your current working path.
For example this working tree:
Project
|->src
| |-->MyClass.java
| |-->MyFile1.txt
|->res
|->files
|-->MyFile2.txt
You can use new File("MyFile1.txt"); for MyFile1.
or
new File("./res/files/MyFile2.txt"); for MyFile2.
You need to start your path from src. "src/your/path/file.txt". See my answer here
If you have a multi-project setup, it may not be obvious what the "root" directory is for a relative path. In that case, open the Terminal tab in your IntelliJ and see what directory it lands in. That is the "root" directory. Your relative path should start there.

Java - Resources.getresource() java.lang.IllegalArgumentException: resource "file" not found

I'm calling the generateTopKFrequentPattern() method of FP growth mining in the Apache Mahout library. In that call, when I use Resources.getResource("FILENAME"), I get the above error saying the file is not found.
My directory structure is Application/src/FILENAME. In the Eclipse window, from run configurations, the default classpath is "Application". I tried using an absolute classpath, "Application/src/FILENAME" and "src/FILENAME". I Still have the same error.
Can anyone please help me with this?
#Thilo, /FILENAME didn't work.
The file should be in the same folder as the classpath (location of the .class file). Either moving the data file to the location of classpath or changing the location of classpath to that of the data file solved the error.
Earlier I had set the classpath location same as the data file location. Somehow, the configuration was reset in Eclipse.
In my case the classpath is "Application/bin" and file is in "Application/src/FILENAME". Specifying file path relative to classpath say "../src/FILENAME" or "/../src/FILENAME" also didn't work for me.
The issue is that the resource, in this case the file, is not in the build path.
If you are using Eclipse, right click the file, and select Add to Build Path.

Unable to download file via VFS in windows machine?

I'm downloading a file from the FTP server using the below
StandardFileSystemManager -> resolveFile and copyFrom(fileobject, Selectors.SELECT_SELF)
The local folders were created automatically and file has been successfully downloaded in LINUX machine.
When i executed the same operation in windows machine i got the following exception, because it is a relative path, and no base URI was provided
org.apache.commons.vfs.FileSystemException: Could not find file with URI "/mnt/shared/\test\sample\files\monday\34.csv" because it is a relative path, and no base URI was provided.
Could you please let me know your thought and suggestions?
Thanks,
Kathir
Please specify your Windows path with forward slash as well. resolveFile() expects URIs not local files. You can use fo = manager.toFileObject(new File("test\\bla.txt")) instead of resolveFile if you insist on windows native (in this case relative) path.

FileNotFoundException in Netbeans

I have a java application project in Netbeans. I have just one class.
I try to do this
FileReader fr = new FileReader("sal.html");
I have the file sal.html under the same package. But I get this error when I run:
Errorjava.io.FileNotFoundException: sal.html (The system cannot find the file specified)
My guess is that Netbeans is invoking the JVM from your project's root folder. Quoting a portion of the File Javadoc:
By default the classes in the java.io package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked.
To verify relative path resolution you could try:
System.out.println(System.getProperty("user.dir"));
System.out.println(new File("sal.html").getAbsolutePath());
You could then move your file to wherever java is looking for it. Most probably your project's root folder.
You could also consider using the class loader to read files as resources inside packages using getClass().getResourceAsStream("sal.html");. This is the preferred way of accessing resources since you no longer have to worry about absolute vs. relative paths. If a resource is in your classpath, you can access it. See this answer for more.
Put your file to main project folder. Not to any sub folders like src, or bin etc. Then it will detect your file.
Click on file view in Netbeans. Move sal.html to the project folder. Such that you will see it like this
- JavaProject
+ build
+ lib
+ nbproject
+ src
+ build.xml
manifest.mf
sal.html
Now
FileReader fr = new FileReader("sal.html");
will work.
System.out.println(System.getProperty("user.dir"));
System.out.println(new File("sal.html").getAbsolutePath());
Then it will show where the JVM is retrieving the files from. Usually for linux in the /home/username/NetbeansProjects/ApplicationName/.
Put your resources or files to this path
I think your problem is in the relative path to the file. Try to declare FileReader with full path to file.
FileNotFoundException means file not found.
The build folder for the netbeans is different where there is no file sal.html.
Try using absolute path in place of using relative path.
This is not a "File not found" problem.
This is because each class hold its own resources (let it be file, image etc.) which can be accessed only through a resource loader statement which is as below:
InputStream in = this.getClass().getResourceAsStream("sal.html");
The only fix is that you will get an InputStream instead of a file.
Hope this helps.

Categories

Resources