code for recently created file from a folder in java

Ads

 
 

Share on Google+Share on Google+

siva
code for recently created file from a folder in java
1 Answer(s)      8 years ago
Posted in : Java Beginners
Ads
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

Ads









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
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
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
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... can check if a folder exists or not in Java. A new Java project is created... 'folder check'. A new package is also created by clicking on the file - new
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 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
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
Folder in Java.
Folder in Java.  I have any problem how to make Folder in java program? Can Anybody help me in this part
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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