Реализация аналога команды ls
This commit is contained in:
@@ -1,13 +1,25 @@
|
|||||||
package ru.spbstu.telematics.java;
|
package ru.spbstu.telematics.java;
|
||||||
|
|
||||||
/**
|
import java.io.File;
|
||||||
* Hello world!
|
|
||||||
*
|
public class App {
|
||||||
*/
|
public static void main(String[] args) {
|
||||||
public class App
|
String path = (args.length > 0) ? args[0] : ".";
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
File directory = new File(path);
|
||||||
{
|
|
||||||
System.out.println( "Hello World!" );
|
if (directory.exists() && directory.isDirectory()) {
|
||||||
|
File[] files = directory.listFiles();
|
||||||
|
|
||||||
|
if (files != null) {
|
||||||
|
for (File file : files) {
|
||||||
|
System.out.println(file.getName());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("Ошибка при чтении содержимого директории.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("Директория не существует или путь указан неверно.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user