简体   繁体   English

当我写导入java.io. *时显示错误;

[英]Show error when i wrote import java.io.*;

why i am getting error when i write import java.io.*; 为什么在编写import java.io. *时出现错误? in java file ? 在java文件中?

dev_ps@DPS:~/Desktop/MorningDose$ javac dev.java
----------
1. WARNING in /home/dev_ps/Desktop/MorningDose/dev.java (at line 2)
    import java.io.*;
           ^^^^^^^

The import java.io is never used

With javac you're compiling your program, you're not running it! 使用javac您正在编译程序,而没有运行它!

after using the command javac dev.java a class file dev.class is created. 使用命令javac dev.java后,将创建一个类文件dev.class If you have defined a main method in the java file you can execute the java-program with the command: 如果您在java文件中定义了main方法,则可以使用以下命令执行java程序:

java dev

In order to understand the difference between compilation and execution you should defenetly read something about these two topics! 为了理解编译和执行之间的区别,您应该认真阅读有关这两个主题的内容!


To your original question: 对您的原始问题:

The import java.io is never used is a warning which tells you that you use no functionality from java.io . The import java.io is never used一个警告,它告诉您您没有使用java.io功能。 That means you can delete the line import java.io.*; 这意味着您可以删除行import java.io.*; (or any alike that isn't used) from your code! (或任何未使用的类似代码)!

It is warning you that you are not using the import, so it is useless. 警告您不要使用导入,因此它没有用。 It will still run with this, but generally it is considered correct to only import what you use. 它仍将与此一起运行,但是通常仅导入您使用的内容被认为是正确的。

Its only a warning, Java compiler warning you because, your not using any class from java.io package. 它只是一个警告,Java编译器警告您,因为您没有使用java.io包中的任何类。 The good practice is remove all un used imports from your classes. 好的做法是从类中删除所有未使用的导入。 Otherwise it will load all the classes while class load time when application start to execute. 否则,它将在应用程序开始执行时在类加载时间加载所有类。

Also if you want to load any class from other package declare only to specific class for eg: if your using BUfferedReader, use as follow 另外,如果您想从其他包中加载任何类,则仅声明为特定类,例如:如果您使用BUfferedReader,请按照以下说明使用

import java.io.BufferedReader; 导入java.io.BufferedReader;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM