-2

I have tried three different projects and tested them but none of them is working..

  • While trying to write to a file I get "java.nio.file.NoSuchFileException";
List<String> contents = Arrays.asList("Hey, there!", "What's up?");
Files.write(Paths.get("C://Users//*****//Documents//NetBeansProjects//SelTest‪//output.txt"), contents);

Java output:

Exception in thread "main" java.nio.file.NoSuchFileException: C:\Users\*****\Documents\NetBeansProjects\SelTest‪\output.txt

I have that output.txt file created and ready.

One more error, While trying to save an image from a BufferedImage, My code was executed successfully but nothing was created?

ImageIO.write(outputImage, "jpg", new File("C:\\Users\\****\\Documents\\NetBeansProjects\\SelTest‪\\love.jpg"));

I can display the BufferedImage as a label and it is rendered fine but ImageIO.write, show no error code successfully executed but no file created!

The last thing I tried today, was reading Selenium driver. I have set the driver path well and it is in right place but still doesn't get the driver.

System.setProperty("webdriver.edge.driver", "C:\\Users\\*****\\Documents\\NetBeansProjects\\SelTest‪\\msedgedriver.exe");
WebDriver driver = new EdgeDriver();

JavaOutput

Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Users\*****\Documents\NetBeansProjects\SelTest‪\msedgedriver.exe
    at com.google.common.base.Preconditions.checkState(Preconditions.java:585)

I'm using Apache NetBeans IDE 12 and my Java:

openjdk version "11.0.11" 2021-04-20 LTS
OpenJDK Runtime Environment (build 11.0.11+9-LTS)
OpenJDK 64-Bit Server VM (build 11.0.11+9-LTS, mixed mode)
Br.GH
  • 27
  • 1
  • 8

2 Answers2

0
  1. your absolute path slash must be back slash.
  2. if render image is empty or null then nothing will be happend Parameter im: @org.jetbrains.annotations.NotNull
Abdul Rafay
  • 131
  • 5
  • On Windows either slash is fine as `Path.of("C:/")` is same as `Path.of("C:\\")` – DuncG Jul 22 '21 at 15:56
  • then he's passing a different/non-existing path – Abdul Rafay Jul 22 '21 at 16:05
  • Hello Abdul, I forgot to mention that either in both ways, back slash or not is fine.. it still same... About the image, it is not image I could make a label and add it on the label as an ICON from the same BufferedImage value. so it is not empty. – Br.GH Jul 22 '21 at 21:58
  • okay then check your security permissions of working directory. maybe write permission not allowed. – Abdul Rafay Jul 23 '21 at 04:53
  • IF you mean on Windows.. it is all allowed and working fine but not sure what is really wrong! – Br.GH Jul 24 '21 at 14:29
  • I had also face this issue on the client side. where the programs files folder have only read access. – Abdul Rafay Jul 24 '21 at 15:15
0

Focus on one question at a time. The Files.write method does not create folder structure for you so gives java.nio.file.NoSuchFileException when the a directory path does not exist.

You can add a step to create the path to the parent folder for the ImageIO and text file example like this:

Path p = Paths.get("C:/Users/*****/Documents/NetBeansProjects/SelTest‪/output.txt");
Files.createDirectories(p.getParent())
Files.write(p, contents);

You do not need to use double slash // in paths on Windows.

DuncG
  • 12,137
  • 2
  • 21
  • 33
  • Thank you DuncG, My problem is not that... Using // or \ or / doesn't make any difference. The directory exists and I even created the output.txt file myself manually to see if that will help. it doesn't even help even, it still shows the same error I feel there is something related with either permission or Java on windows – Br.GH Jul 22 '21 at 22:01