-1

I am using Eclipse,I wanted to create a new File in my Web Project .

My Eclipse Location is

Path:"H:\\eclipse\\New folder\\Testing_Project\\WebContent\\";
File:1.jsp(New File to be created)

File create=new File(Path,File);
create.createNewFile();

But it is saying that File is not created .It is saying the error as "(The filename, directory name, or volume label syntax is incorrect)"

Is there any way i can create a File in Java.

4
  • 5
    stackoverflow.com/questions/2885173/… Commented Nov 27, 2015 at 6:51
  • @KumarSaurabh i tried those things ,but its not working ,i hope there should be some handling with Eclipse Commented Nov 27, 2015 at 6:52
  • have you tried java's java.nio.file.Files to create a new file? Commented Nov 27, 2015 at 6:54
  • @ArdeshanaMilan no i have not tried it Commented Nov 27, 2015 at 6:55

1 Answer 1

2

Try out this piece of snippet.

try {

      File file = new File("H:\\eclipse\\New folder\\Testing_Project\\WebContent\\");

      if (file.createNewFile()){
        System.out.println("File is created!");
      }else{
        System.out.println("File already exists.");
      }

    } catch (IOException e) {
      e.printStackTrace();
Sign up to request clarification or add additional context in comments.

2 Comments

i wanted to create a file named "1.jsp" .How to create with that Name
File file = new File("H:\\eclipse\\New Folder\\Testing_Project\\WebContent\\1.jsp"); I think :) Btw try to search first time, before you ask - look on posts like stackoverflow.com/questions/6142901/… or stackoverflow.com/questions/2885173/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.