Hi,
I wanted a simple java program for web services development as per below:
------ IN REQUEST ------
FileName - Path of the file (For example: C/text.txt)
------ IN RESPONSE --------
FileName: This should be filename same as input. Size: size of the file in KB. Type: Type of the file i.e. Java File, ..or anything like. ReadAccess and WriteAccess: Boolean - True or false depending upon access rights. LastModified - Timestamp in the format ddMMyyyy'T'hhmmss
Please help me to get this done.
Thanks
The given code allow the user to input file name with path. The code will then determine the size of file, name of file, last modified date of file. It also check whether the given file is readable or writable.
import javax.swing.*; import java.util.*; import java.text.*; import java.io.*; public class FileOperations{ public static void main(String[]args){ File f=new File("c:/data.txt"); long size=f.length(); String name=f.getName(); JFileChooser chooser = new JFileChooser(); String fileType= chooser.getTypeDescription(f); boolean check1=f.canRead(); boolean check2=f.canWrite(); long s=f.lastModified(); Date d=new Date(s); SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy hh:mm:ss"); String lastmodified=sdf.format(d); System.out.println("File Name: "+name); System.out.println("File Type: "+fileType); System.out.println("Is file Readable: "+check1); System.out.println("Is file Writable: "+check2); System.out.println("Last Modified Date: "+lastmodified); } }
Ads