-1

I am using following code to create a text file on remote window server:

String archiveFolder=\\etld90\\DM;
new File(archiveFolder + File.separator + "done" + ".txt");

Its not giving any error but also not creating a file.

6
  • Your code is not supposed to create anything other than a new File object in memory that is immediately discarded. Commented Jan 15, 2020 at 21:04
  • Please suggest how to achieve. Commented Jan 15, 2020 at 21:07
  • How do you connect with this remote server, via ssh? You can take a look on this jcraft.com/jsch Commented Jan 15, 2020 at 21:08
  • Follow the link I provided. Commented Jan 15, 2020 at 21:12
  • Code is on my local PC and i have all permission on specified folder Commented Jan 15, 2020 at 21:15

1 Answer 1

0

This only creates the File object in memory

createNewFile() - "Atomically creates a new, empty file named by this abstract path name if and only if a file with this name does not yet exist"

Here's some code demonstrating it

  File myObj = new File("filename.txt");
  if (myObj.createNewFile()) {
    System.out.println("File created: " + myObj.getName());
  } 
  else {
    System.out.println("File already exists.");
  }
Sign up to request clarification or add additional context in comments.

5 Comments

I am getting error java.io.IOException: The system cannot find the path specified.
Does the directory you are setting exist? Also I would recommend wrapping that code block with a try-catch so you can handle that IOException.
Yes,it exists.I am just creating a new file there.
You can try to use myObj.getParentFile().mkdirs(); to create the required directory
Directory already exists.Do we need any kind of permission.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.