-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.

VijayManohar7
  • 123
  • 2
  • 11

1 Answers1

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();
Kulasangar
  • 9,046
  • 5
  • 51
  • 82
  • i wanted to create a file named "1.jsp" .How to create with that Name – VijayManohar7 Nov 27 '15 at 06:55
  • `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 http://stackoverflow.com/questions/6142901/how-to-create-a-file-in-a-directory-in-java] or http://stackoverflow.com/questions/2885173/how-to-create-a-file-and-write-to-a-file-in-java – xxxvodnikxxx Nov 27 '15 at 07:37