Java - Web Service code that allow the user to input file name with path

Java - Web Service code that allow the user to input file name with path

Hi,

I wanted a simple java program for web services development as per below:

------ IN REQUEST ------ <FileName>

FileName - Path of the file (For example: C/text.txt)

------ IN RESPONSE --------

<FileName> <Size> <Type> <ReadAccess> <WriteAccess> <LastModified>

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

View Answers

May 12, 2012 at 4:17 PM

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);
    }
}









Related Tutorials/Questions & Answers:
Getting ISD code when user input country name
code, from that list i have to read the file and when user input any country name...Getting ISD code when user input country name  I want to create program which user needs by typing Country name he will get ISD code of that country
Constructing a File Name path in Java
is helpful for mapping local  file name with the actual path of the file using...: C:\java>java ConstructingFileNamePath The path of the file is : \tapan... Constructing a File Name path    
Advertisements
Constructing a File Name path
Constructing a File Name path   ... construct a file name path. By using the constructing filename path it is possible to set dynamic path, which is helpful for mapping local  file name
need solution to get file name from path which should give by user
need solution to get file name from path which should give by user  how do i write a program in java that i should get file path from arguments.currently this code creates the file at d:\ but i need to get this file name
Getting path name of uploading file in struts 2.8.1
Getting path name of uploading file in struts 2.8.1  Hai! I am using struts 2.8.1. I want to upload file into database with the path name. How can I can get the original path name of the file in struts 2.8.1? It only display
Getting path name of uploading file in struts 2.1.8
Getting path name of uploading file in struts 2.1.8  In my question I used struts 2.8.1 instead of 2.1.8. Sorry
Java User Input
Java User Input  I am using Scanner class for user Input. Scanner s = new Scanner(System.in); String name = s.next(); but i am unable to store full name in name variable...how i can store full name plsss reply   use
How to get the full path location using <input type=file>
How to get the full path location using input type=file  Hi. I have used input type=file> in HTML to select an image. But it selects only the image but not with its full path location. how to do it? Thanks in advance
Java Construct File Path
Java Construct File Path In this section we will discuss about how to construct file path in Java. A file path can be constructed manually or by a Java program. It is best practice to construct a file path in Java by a Java Program
Read user input in Java using Scanner
Example of of reading user input in Java using Scanner In this section we... input from console. Our sample program asks user to enter name and then age, user... back on the console. There are various ways to read user input in Java
java user input - Java Beginners
java user input  how to input from keyboard? please give a example.  Hi Friend, There are lot of ways to input data from keyboard.You...:****** try{ System.out.print("Enter String:"); BufferedReader input = new
Java get User Input
Java get User Input       In this section, you will learn how to get the user input from... that will communicate with the user at the command line and returns the user input. We have
How to retrieve file name and path of an excel spreadsheet imported into Oracle Database
How to retrieve file name and path of an excel spreadsheet imported into Oracle... Oracle database and I want to know how to retrieve the path of the file... table for each spreadsheet but I want to obtain the path and filename of each
user input in java - Java Beginners
user input in java   i am trying to write a code to compute the average of 5 numbers but i dont know what to do for the program to accept user input  Hi import java.util.*; public class AverageExample { public
How to store user name,city,state,image path into database and image into folder using jsp
How to store user name,city,state,image path into database and image into folder using jsp  How to store user name,city,state,image path into database and image into folder using jsp
How to create file and save it into user defined path using jsp/servlet?
How to create file and save it into user defined path using jsp/servlet?  Hi.. Onclick event I have created one file.When file will create it should asked where to save file(like browse option
Java Get File Name
Java Get File Name       In this section, you will study how to obtain the name of file.  In order to get the file name, we have provided the path of file 'Hello.txt
File Path compare in java
File Path Comparison :compareTo      File Path Comparison :compareTo...;); } } } Output : If both path name are same : Both
Java class name and file name are different
Java class name and file name are different  Can we run a Java program having class name and file name different?   Hi Friend, No, you can't. It is necessary to save the java file with its class name otherwise
Java file absolute path
Java file absolute path In this section, you will learn how to get the absolute path of the file. Description of code: If you want to locate a file without... created an object of File class and passed the name of the file as an argument
Convert a file name path to url and vice versa in java
the Filename Path into URL. It reads a file name and converted into the URL. toURL(): The toURL() method of the File class is used to convert the file name... with the toURL() method of the File class. Here is the code of Convert the Filename
escaping user input in php
escaping user input in php  Is it possible to escape the user input while submitting data into database in PHP
File path for jar file
not found for the template file. Also I had tried to get that path from user...File path for jar file  Hi Experts, I have created one eclipse... path of the template, which is working as per expectation. But I have created
No SDK with the name or path
Missing or No SDK with the name or path for XYZ version follow the steps below...No SDK with the name or path  When i run any downloaded application on my mac professional ..it always returns a message no sdk with the name
Take input in batch file
Take input in batch file  How to take input in batch file? Thanks   Hi, You can use the following line of code in your batch file: set /p myfile=Enter file name: In the above code myfile variable will hold the data
SWT File Browser
, the class FileDialog allow the user to navigate the file system and select a file...;= new File(path);   if (file.isFile())   ... SWT File Browser     
button to accept user input
the radiobutton and spinner.The user input does not show on my Studentinfo.mdb...button to accept user input  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){ public string name,lastname,radiobutton,spinner
How to compile PHP file and provide it to user without code?
How to compile PHP file and provide it to user without code?  I have... in asp.net instead of providing code file. How can I compile the PHP file and provide it to my user in the form dll or may be with other type or extension? Please
calculation after if. user input
user input????   My apologies good evening peoples Once again I am...calculation after if. user input  System.out.print ("please select... addition 5 errors found: File: C:\Users\ Error: variable appleCost might not have
user input to database
user input to database  /* * Studentinfo2App.java */ package...) { } return 0; } } could you plz check what is wrong wit my code because in my database user input from my applet does not show
user input to database
user input to database  /* * Studentinfo2App.java */ package...) { } return 0; } } could you plz check what is wrong wit my code because in my database user input from my applet does not show
user input to database
user input to database  /* * Studentinfo2App.java */ package...) { } return 0; } } could you plz check what is wrong wit my code because in my database user input from my applet does not show
textfield should not allow the user to fill the date in it.
textfield should not allow the user to fill the date in it.  I got a requirement like this, I am dislaying a text field along with a calendar. Here user should not fill the date inside the text field manually. If he tries
How to read user input in C++
How to read user input in C++  How can i get an input from the users in C++?   You can use the standard input "cin" to get the input from user.. For example: int age; cin >> age
to retrive e mails as per user name - Java Beginners
to retrive e mails as per user name  hi friends, how to retrive e mails as per user "user name " for ex: class Mail{ private String subject... MailRetriever{ public Mail[] getAllMails(String userName){ //Write code
PHP hide file path
PHP hide file path  PHP to read a path and convert that to the virtual link
how to get java path name
Java file get name
Java file get name In this section, you will learn how to get the name of the file. Description of code: You can see in the given example, we have created... the name of the file.ADS_TO_REPLACE_1 Here is the code: import java.io.
Read File from specified path in Java
How to read a file from a specified path in Java? After learning so many... reads a text file from specified path in Java. We will give complete path...: You can also read the file using the Scanner class of Java. Here is the code
code to upload and download a file - Java Magazine
different files with same path name but content different, ex,in mails, one user send one a.doc file to x ,he has to download his a.doc another user sends...code to upload and download a file  Is their any code to upload
java code to upload and download a file - Java Beginners
java code to upload and download a file  Is their any java code... store two different files with same path name but content different, ex,in mails, one user send one a.doc file to x ,he has to download his a.doc another
Problem in getting file path in js
Problem in getting file path in js  hi, I am using ofbiz framework , How i can get the file path in javascript for input type = "file" and i am using only firefox not other browser. so please help me it is very important for me
why java file save as its class name
why java file save as its class name  hi,this is subbareddy vajrala.my doubt is why java files save as its class names
how to use StringTokenizer to retrieve the class name, attributes name and methods name from the Java Source Code
how to use StringTokenizer to retrieve the class name, attributes name and methods name from the Java Source Code  hi, I have done a program whereby it can read a Java file and then tokenize them into tokens. However, I am facing
Servlet Error Message based on user input
;test.jsp" which renders an input field to enter the name of the user...Servlet Error Message based on user input   ... to check the user input against database and display the message to the user
write a java program to print marklist of n students. input Register number, name and marks of three subjects.
write a java program to print marklist of "n " students. input Register number, name and marks of three subjects.  write a java program to print marklist of "n " students. input Register number, name and marks of three subjects
java code that monitors the mic input, and dims the screen accordingly
java code that monitors the mic input, and dims the screen accordingly  I know the very basic syntax of java, could someone help me write a code that would constantly analyze the sound being taken in by the mic on the computer
how do i allow users to download a xls file in html?
how do i allow users to download a xls file in html?  can anyone help me to allow users to download a xls file in html? i tried with href="path...;i tried with href="path/filename.xls click here but it works only in chrome
Java Naming and Directory Interface (JNDI)
name service File system JNDI hierarchally organizes its name...) is a directory service based API to allow the clients to discover and lookup data... or for a flat file or for a database for implementation. RMI and Java EE uses
XP Bowling Game User input help
to make the code accept input from a user and display the scores/frames in a command window. Being new to Java....I have no clue how to out put it to the console...XP Bowling Game User input help  I was asked to do the XP Bowling

Ads