问题
So I'm working on reading in a ".txt" file to use it to implement Dijkstra's algorithm, but every time I try to compile it gives me a "FileReader is already defined in this compilation unit" error while highlighting where I imported it in the beginning. If I take this out, however, it throws a constructor error when I'm trying to read in the file that it's of the wrong type. What am I missing here??
Here is my code:
import java.io.BufferedReader;
import java.io.File;
//import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class FileReader
{
public ArrayList main1()
{
System.out.println("got here");
try
{
BufferedReader in = new BufferedReader(new FileReader(new File("input1.txt")));
I can provide more if needed, but this is where all of the errors crop up.
回答1:
Your class is named the same as FileReader in the java.io package (you have commented out above). Rename your class to something else like TextFileReader or InputFileReader or use the fully qualified class name for java.io.FileReader.
回答2:
Just rename your class "FileReader" to different toxicity, in order not to be confused.
来源:https://stackoverflow.com/questions/37141863/filereader-is-already-defined-in-this-compilation-unit-error-java