Adding a File

See Also

When you add a file to your project, it is included in the project's build process. Adding a file to a Java project also adds the file to the project directory structure on the hard disk:

Note   Some files may reside in the project directory structure without belonging to the project. For example, removing a file from the project still leaves the file in the project directory structure. This file can be added back to the project in its same location on the disk.

You can add a file to the top-level project or to a specific folder. For information about adding folders to the project, see Adding a Folder.

To add a file to the project

  1. In Project Explorer, select the project or folder node that will contain the file.

  2. On the Project menu, click Add Item.

  3. To create a new file, click the New tab in the Add Item dialog box.
  4. To add an existing file, click the Existing tab in the Add Item dialog box.

When a single file is added to the project through Project Explorer, it is automatically opened in its default editor. When multiple files are added at the same time, no file is opened. For information about opening files, see Opening a File.

Note   If a file is added to the project directory structure through the file system, it is automatically added to the project if its file type is specified in the project filter. The file is then displayed in Project Explorer, but not opened. For more information about the project filter, see Displaying All Files in the Project Directory Structure.

Adding a File that Resides in the Project Directory Structure

If a file does not belong to the project, but it already exists in the project directory structure, you can simply add it to the project in that same location.

To add a file that already resides in the project directory structure

  1. Set the project view to directory view by clicking the Directory View button in Project Explorer. Only directory view allows you to see the nonproject files that reside in the project directory structure. For more information about views, see Choosing the Project View.

  2. If the nonproject files are not currently displayed, click the Show All Files button in Project Explorer to show all files in the project directory structure.

  3. Right-click the name of the file that you want to add to the project. Note that you cannot add a file if its folder is not in the project. For information about adding the folder, see Adding a Folder that Resides in the Project Directory Structure.

  4. On the shortcut menu, click Add To Project. The file is added to the project, but not opened. For information about opening files, see Opening a File.

  5. To hide any remaining nonproject files, click the Show All Files button again.

For more information about nonproject files that reside in the project directory structure, see Displaying All Files in the Project Directory Structure.