Professional Documents
Culture Documents
نسخة من Lab04- sol
نسخة من Lab04- sol
1- Write a Java program that reads a file name from the user then
displays information about whether that file exists, file is writable, the
type of file and length of the file in bytes.
import
. java.io.*;
2- Write a Java program that displays the name and date of the last
modified file among a group of files in the folder,
import java.io.*;
import java.text.SimpleDateFormat;
}}
}
3- Write a Java program that displays the information of the largest size
file among a group of files in the folder
import java.io.*;
import java.text.SimpleDateFormat;
}
}
System.out.println ("File size =" + Filesize +" File Name: " + files + "Last modified =" +
last);
}
4- Write a Java program that displays the files name which has
[txt] or [docx] extension.
import java.io.*;
import java.text.SimpleDateFormat;
if(folder.exists())
{ ArrayList <String> filesName = new ArrayList <String>();
int j =0;
for (int i = 0; i < listOfFiles.length; i++)
{
if(listOfFiles[i].getName().endsWith("txt")|| listOfFiles[i].getName().endsWith("docx"))
{
filesName.add(listOfFiles[i].getName());
}
}System.out.println(filesName);}
}}
5- Write a Java program that displays the files name which begin with
[a] character .
import java.io.*;
import java.text.SimpleDateFormat;
if(folder.exists())
{ ArrayList <String> filesName = new ArrayList <String>();
int j =0;
for (int i = 0; i < listOfFiles.length; i++)
{
if(listOfFiles[i].getName().startsWith("A"))
{
filesName.add(listOfFiles[i].getName());
}
}System.out.println(filesName);}
}}