-2

how can I import a file in java programming language

Niya Simon C
  • 279
  • 2
  • 4
  • 10
  • 1
    Your question is not clear. What do you mean with "importing" a file? Please edit your question to clarify. – Jesper Jul 05 '10 at 06:51
  • Unless what he's actually after is "import java.io.File" ? Dunno... – Mala Mar 07 '11 at 06:13

3 Answers3

2

You don't import files in Java. You import classes.

The syntax is as follows:

import com.my.Class;

There is nothing like the #include available in C/C++. If you really want to actually "include" files into your source, you need to rethink your design.

Shirik
  • 3,631
  • 1
  • 23
  • 27
2

If by import a file you meant read a file, there are several ways, probably the most common of which are using the Scanner and BufferedReader objects. Have a look at
http://java.sun.com/javase/6/docs/api/java/util/Scanner.html
and
http://java.sun.com/javase/6/docs/api/java/io/BufferedReader.html
respectively for information on how to use them.

Mala
  • 14,178
  • 25
  • 88
  • 119