У меня установлен NetBeans на моем диске C. Мой код, открывающий txt, имеет проблему и состоит в том, что он не может открыть txt, сохраненный на диске D, я не знаю, есть ли код, чтобы дать доступ к другой жесткий диск.
По этому пути код может прочитать файл:
String path = "C:\\Users\\ch\\Documents\\Test2.txt";
С этим путем код не может прочитать файл:
String pathdiskd = "D:\\Desktop\\Test2.txt";
код, который я использую, это:
public static LL_Games_Carlos getGames(String path)
{
LL_Games_Carlos llg = new LL_Games_Carlos();
FileInputStream inputStream = null;
Scanner sc = null;
String sep = "--------------------------------------------";
try
{
inputStream = new FileInputStream(path);
sc = new Scanner(inputStream, "UTF-8");
String line = sc.nextLine();
String[] s = null;
String idg = null, ids = null, idt1 = null, idt2 = null, d = null;
while(sc.hasNextLine())
{
while(!line.equals(sep))
{
s = line.split("ID Game: ");
if(s.length>1) idg = s[1];
line = sc.nextLine();
s = line.split("ID Stadium: ");
if(s.length>1) ids = s[1];
line = sc.nextLine();
s = line.split("ID Team 1: ");
if(s.length>1) idt1 = s[1];
line = sc.nextLine();
s = line.split("ID Team 2: ");
if(s.length>1) idt2 = s[1];
line = sc.nextLine();
s = line.split("Date Game: ");
if(s.length>1) d = s[1];
line = sc.nextLine();
}
if(sc.hasNextLine())
line = sc.nextLine();
llg.Insert(Integer.parseInt(idg), Integer.parseInt(ids), Integer.parseInt(idt1), Integer.parseInt(idt2), LocalDate.parse(d));
}
}
catch(FileNotFoundException e)
{
System.out.println("File not found. MSJ: \n" + e);
}
finally
{
if(inputStream!=null)
{
try
{
inputStream.close();
}
catch(IOException e)
{
System.out.println("IO Exception. MSJ: \n" + e);
}
}
if(sc!=null)
{
sc.close();
}
}
return llg;
}