Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners code for recently created file from a folder in java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


siva
code for recently created file from a folder in java
1 Answer(s)      6 years and a month ago
Posted in : Java Beginners



Advertisement
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
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
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
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
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
Folder in Java.
Folder in Java.  I have any problem how to make Folder in java program? Can Anybody help me in this part
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
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
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 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
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 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
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
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
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
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 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 backup files and folder with Java
how to backup files and folder with Java  Does anyone know to create a backup with java?. backup files and folders from my computer to an external drive.   hi friend, Try the following code may, this will be helpful
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
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
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. In the Autorun.inf file you can include
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
Zipping folder - Java Beginners
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... solve this.. zipping folder and all of its files and sub folders. thanking
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
 

 

 

DMCA.com