Advertisement
sergAccount

Untitled

Dec 6th, 2020
868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package app9;
  7.  
  8. import java.io.File;
  9.  
  10. public class App9 {
  11.    
  12.     public static void main(String[] args) {
  13.         // TODO code application logic here
  14.         // File
  15.         File f = new File("c:/test");
  16.         // используем метод для определения сущ-я файла или папки
  17.         boolean value = f.exists();        
  18.         if(value){
  19.             System.out.println("Папка c:/test - существует!!!");
  20.         }
  21.         // метод для опеределения типа объекта (файл или папка)
  22.         if(f.isDirectory()){
  23.             System.out.println("c:/test - папка!");
  24.         }
  25.         File f2 = new File("c:/test/test.txt");
  26.         if(f2.isFile()){
  27.             System.out.println("c:/test/test.txt - файл!");
  28.         }
  29.         // получим список объектов для определнной папки
  30.         String[] array = f.list();
  31.         for (int i = 0; i < array.length; i++) {
  32.             System.out.println("array[i]=" + array[i]);            
  33.         }        
  34.     }
  35.    
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement