code for recently created file from a folder in java

code for recently created file from a folder in java

View Answers

December 19, 2008 at 4:28 AM

Hi friend,

Code to help in solving the problem :

import java.io.*;

import java.util.Date;

public class TraversingFileAndDirectories{

public static void main(String args[]){

String dirname = args[0];

long tmp=0;
String fileName="";
try
{
File file = new File(dirname);

if(file.isDirectory()){

System.out.println("Directory is " + dirname);

String str[] = file.list();

for( int i = 0; i<str.length; i++){

File f=new File(dirname + " / " + str[i]);

if(f.isDirectory()){

System.out.println(str[i] + " is a directory");

}

else{

Long lastModified = f.lastModified();
if(lastModified>tmp)
{
tmp = lastModified;
fileName=dirname + " / " + str[i];
}
System.out.println(lastModified);


}

FileInputStream finp=new FileInputStream(fileName);
byte b;
do{
b=(byte)finp.read();
System.out.print((char)b);
}
while(b!=-1);
finp.close();
}

}

else{

System.out.println(dirname + " is not a directory");

}

}
catch (Exception e)
{
System.out.println(e.getMessage());
}


}

}

Thanks









Related Tutorials/Questions & Answers:
code for recently created file from a folder in java - Java Beginners
code for recently created file from a folder in java  how to get the recently created file from a folder in java?  Hi friend, Code...=""; try { File file = new File(dirname); if(file.isDirectory
copy file from folder to folder - Java Beginners
copy file from folder to folder   my requirement is I need to copy xml files from one folder to another my source file contains the field filename wich contains the file to be copied. I want to copy the file from
Advertisements
how to download a file from a folder??
how to download a file from a folder??  i can upload any kind of files to a folder, and only the path of the file is saved into the database, now how a client can download the file from my folder. pls provide me the jsp code
Java lock file or folder.
Java lock file or folder.  Is it possible to create a desktop application to lock or encrypt file or folder in windows by using java code?? if possible can provide some reference?? because i can't find it... thanks
how to upload a file of apk format in a folder from servlet
how to upload a file of apk format in a folder from servlet  How to upload a file of apk format to a folder from servlet, i am trying to do, its getting uploaded as .zip file and not apk file
create table in mysql of split file created in java
create table in mysql of split file created in java  i have created splite file in java. now i want to create table from splited data how to do
Image is in same folder where the java file is located - Swing AWT
Image is in same folder where the java file is located  dear sir It is there in the same folder..means the photograph.jpg file is created in the same folder where my java file is present... wat I should do sir
Video Tutorial: How to check if a folder exists in Java through a source code
How to check if a folder exists in Java through a source code Java is an all... project is created by clicking on the file - new - project -Java project - next... we can check out if our folder exists in Java by the help of source code
download xml file from website using java code
download xml file from website using java code  how to download xml file from website using java code
downloading created xml file - Java Beginners
downloading created xml file  Hi... I've an application where i need to create an xml file and when a button is clicked it has to prompt me for saving the xml file so i created xml file successfully and whats the problem
How to upload and save a file in a folder - Java Beginners
and save a file in a folder? for example Agreement.jsp File: So when... should be able to access the file. Can u please tell me the code..  ..., Thanks for your code.... Do i need any jarfiles to be placed in lib? Java
How to access the image file from project folder itself while writing to pdf using itext?
How to access the image file from project folder itself while writing to pdf... it to pick it up from the project folder itself.Because later i deploy the project...:\\company.jpg"); it works fine But when i use this code image = Image.getInstance("items
How to read PDF files created from Java thru VB Script
How to read PDF files created from Java thru VB Script  We have created the PDF file thru APache FOP but when we are unable to read the data thru... file?   Java PDF Tutorials
I want to Transfer only 1/3rd of contents from one folder to other but my code is transferring all contents
I want to Transfer only 1/3rd of contents from one folder to other but my code...(File src, File dest) throws IOException { if (src.isDirectory()) { dest.mkdir(); File[] entries = src.listFiles
passing parameter from Java code to CSS file - Design concepts & design patterns
passing parameter from Java code to CSS file  hi, i have to pass a string variable from by java code to a CSS file so that i can use that variable in my CSS file. Plz help me as soon as possible
Folder in Java.
Folder in Java.  I have any problem how to make Folder in java program? Can Anybody help me in this part
Read from file java
Read from file java  How to Read from file java? What is the best method for a text file having a size of 10GB. Since i have to process the file one line at a time so tell me the very best method. Thank you
Java sdk/java poi hssf code to creat excel with folder structure,( i,e folders, subfolders and childrens )
Java sdk/java poi hssf code to creat excel with folder structure,( i,e folders... in the excel file . To be precise, am working on Java sdk of business objecsts . i need some help in getting folder structure using this java . Folder
Create new file in java
create main method than we use try and catch block. We have created File object in java File class representing the files and folder pathnames by location...Create new file in java We are going to discuss how to create new file in java
Java code to convert pdf file to word file
Java code to convert pdf file to word file  How to convert pdf file to word file using Java
Delete image from folder - JSP-Servlet
when user will logout using java code. anybody having idea about then please...Delete image from folder  Dear All, i used some coding.... that image name based on user id and that image is going to on folder in server after
How to delete file in Java code?
How to delete file in Java code?  Hi, From my Java program I have to delete a file. How to delete file in Java code? Thanks   Hi, Java... complete example code at How to delete file in Java?. Thanks   Hi, Also
How to copy files from one folder to another based on lastmodified date - Java Beginners
Copy files from one folder to another  How to copy files from one folder to another based on lastmodified date
How to copy files from one folder to another based on lastmodified date - Java Beginners
How to copy files from one folder to another based on lastmodified date  I have to make a simple utility to copy files from a folder to another folder in the same hierarchy, without overwriting the existing.  hiimport
Executing code upon folder/drive access
Executing code upon folder/drive access  I would be glad if someone could show me how to make your program in jar format execute when the folder... of drive you can use Autorun.inf file.ADS_TO_REPLACE_1 In the Autorun.inf file
Java read lines from file
Java read lines from file  Any code example related to Java read lines from file? In my project there is requirement of reading the file line by line... of reading file line by line in Java. Can any one share me the code for reading
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?  i have multiple(app..100) text... column value that keeps on changing for every file.i have read the data from all
Reading a file from Jar JAVA
Reading a file from Jar JAVA  I have added one excel sheet into a jar file. can anybody tell me how i can read that file. actually when i am running code from eclipse i able to read it but when i am adding that jar file
Reading a file from Jar JAVA
Reading a file from Jar JAVA  I have added one excel sheet into a jar file. can anybody tell me how i can read that file. actually when i am running code from eclipse i able to read it but when i am adding that jar file
How to download a file from URL in Java?
How to download a file from URL? If you are looking for example code in Java... is for you. You will learn how to write code in Java for downloading a file from URL... to write a code in Java which takes file URL, local file name and destination
How many objects are created in the code below? Explain.
How many objects are created in the code below? Explain.  Hi, Here is my code public static void main(String[] args) {String s1 = "abc"; StringBuffer s2 = new StringBuffer(s1); StringBuffer s3= s2; StringBuffer s4 = new
Zipping folder - Java Beginners
]; // get a list of files from current directory File f = new File... to zip a user selected folder . this folder may contain any number of folder and sub folders. i saw an example in this site showing , how to zip a folder, i executed
Delete image from folder - JSP-Servlet
).png if you have any java code for deleting this please send me. not JDBC code...Delete image from folder  Hi Thanks Rajnikant to given me reply i am not storing my image in db just userid comming from db means my
Java Write To File From String
Java Write To File From String In this tutorial you will learn how to write to file from string. Write to file from string using java at first we will have... in which I have created a new text file using the File constructor
Count characters from text file in Java
is a java code that count the occurrence of each character from text file. import...Count characters from text file in Java  At the "Count chracters fro mtext file in Java". I tried to run the code, but the error at the line have
Getting the modification date and time of file or folder in Java
C:\nisha>java GetDirectoryAndFileModifiedTime Enter file or directory name in proper format to get the modification date and time : myfile.txt File name : myfile.txt File modification date
image save to folder in java
image save to folder in java  Hi, I am working with java. In my... folder and that path stored into database, for furhter retrivation. Please guide me to overcome from that problem Thanks and Regrads Pushpa sheela
how to display the output of the newly created excel file
how to display the output of the newly created excel file  the following program will create the test.xlsx file, how can i display the content of the test.xlsx file in the web browser? thanks, %@ page import
How to copy an jpeg image from one folder to other folder using jsp
How to copy an jpeg image from one folder to other folder using jsp  How to copy an image from one folder to another folder using jsp
java client server program for playing video file(stored in folder in the same workspace) using swings
java client server program for playing video file(stored in folder in the same... a client server program to play a video file, when I run both client and server... file name"); l.setBounds(50, 30, 100, 50); getContentPane().add(l
java client server program for playing video file(stored in folder in the same workspace) using swings
java client server program for playing video file(stored in folder in the same... a client server program to play a video file, when I run both client and server... file name"); l.setBounds(50, 30, 100, 50); getContentPane().add(l
java client server program for playing video file(stored in folder in the same workspace) using swings
java client server program for playing video file(stored in folder in the same... a client server program to play a video file, when I run both client and server... file name"); l.setBounds(50, 30, 100, 50); getContentPane().add(l
java client server program for playing video file(stored in folder in the same workspace) using swings
java client server program for playing video file(stored in folder in the same... a client server program to play a video file, when I run both client and server... file name"); l.setBounds(50, 30, 100, 50); getContentPane().add(l
Export data into CSV File using Servlet
to Export data into  CSV file using Servlet. We have created  file "JdbcCsvFile.java" to export data from this .java file.. Brief... Export data into CSV File using Servlet  
Character from text file - Java Beginners
Character from text file  Write a program that reads characters from a text file. Your program will count how many time each character appear...: ?The contents of a string cannot be changed once the string is created.? Character
java code to upload and download a file - Java Beginners
java code to upload and download a file  Is their any java code to upload a file and download a file from databse, My requirement is how can i..., one user send one a.doc file to x ,he has to download his a.doc another
java code Translitrator from english to hindi
java code Translitrator from english to hindi  I need help to develop a java translitrator application that transforms english to hindi
parsing xml file using java code
parsing xml file using java code  parsing a xml file using java code
Please help me to modify my java code from php code
Modify Java code from PHP Code  i want to covert this php code int java/JSP. if (isset($_POST['orders'])) { $orders = explode('&', $_POST...]; } } I tried like this (see below JSP code) ... but this is not giving me
Read file into byte array java code eample
Read file into byte array java code eample  Hi, I have a project where I have to write for that reads file into byte array. I want a code java code for reading file into byte. Just let's know the best code. Thanks   

Ads