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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Shibin Varghese
Java File
1 Answer(s)      5 years and a month ago
Posted in : Java Beginners



Advertisement
View Answers

November 9, 2009 at 11:46 AM


Hi Friend,

Try the following code:

import java.io.*;
class Listing {
String st = "";
File file;
File f;
public Listing(File f) {
this.file = f;
this.f = f;
}
public void displayFiles() {
findFiles(f);
}
public void findFiles(File f){
if (f.isDirectory()){
st = getFiles(f);
System.out.println(st + f.getName());
File files[] = f.listFiles();
for(File ff : files){
findFiles(ff);
}
}else if (f.isFile()){
System.out.println(st + " " + f.getName()+" Size is: "+f.length());
}
}
private String getFiles(File f) {
String originalPath = file.getAbsolutePath();
String path = f.getAbsolutePath();
String subString = path.substring(originalPath.length(), path.length());
String st = "";
for(int index=0; index<subString.length(); index ++){
char ch = subString.charAt(index);
if (ch == File.separatorChar){
st = st + " ";
}
}
return st;
}
}
public class ListAllFiles {
public static void main(String[] args) {
String p = "C:\\" ;
Listing list = new Listing(new File(p));
list.displayFiles();
}
}

Thanks


Related Tutorials/Questions & Answers:
String file in to word file in java
String file in to word file in java  How to convert a String format notepad file into Ms word file in java
String file in to word file in java
String file in to word file in java  how to convert a String format word file into Ms Word file using java? please can anyone of you help me
Advertisements
calling a java file in java
calling a java file in java  how to call a another java file in java
file in java - Java Beginners
file in java  I want to count the number of white line and comment line in a file (.sql) with java if you have an example thank you in advance
Java file class
Java file class  What is the purpose of the File class
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
Convert Class File to .java File - Java Beginners
Convert Class File to .java File  Sir, How To Convert .class file to .java File. Please Help me  Use cavaj software ,which is freeware, to convert .class to .java  Use jd-gui to convert ur .class to .java
Java File - Java Beginners
Java File  Hi Friend, Thank you for the support I got previously... Anyone please send me the Java Code for scanning a directory and print.... Output Print the file names and size of the file to the console. Please
java get file permission
java get file permission  How to check the get file permission in Java
Reading a text file in java
in java.io.* package for reading and writing to a file in Java. To learn more about reading text file in Java see the tutorial Read File in Java. Thanks...Reading a text file in java  What is the code for Reading a text file
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java. Please suggest and give example of this program. thanks
java read file
java read file  Hello i need some help... i want to read an MS Excel file in java so how to read that file
Batch file for java application
Batch file for java application  please tell me how to create the batch file for java application(using swings).the application is created with netbeans
java file handling
java file handling  enter string from keyboard and then read a file if this string is present in file then print message already exists else write this string to file
Read file in java
Read file in java  Hi, How to Read file in java? Thanks   Hi, Read complete tutorial with example at Read file in java. Thanks
Reading big file in Java
Reading big file in Java  How to read a big text file in Java program?   Hi, Read the complete tutorial at How to read big file line by line in java? Thanks
File handling in Java
handling in Java? Thanks   Hi, File handling is very important... such as .properties file or xml file. Java programming language also provide very good file handling features in their api. You can read more at File Handling in Java
Java write to file
Java write to file  How to write to a file in Java? Is there any good example code here? Thanks   Hi, Java is one of the best... Handling examples in Java Java Input/Output Examples How to read file in Java
Java class file
Java class file  How do i open a java class file using eclipse
Execute .dll file in java?
Execute .dll file in java?  please anybody give me solution for executing .dll files in java
How to compress a file in Java?
How to compress a file in Java?  How to compress a file in Java through Java code? I want a good example in Java. Thanks   Hi, Check the tutorial Compressing the file into GZIP format. Thanks
Download a file - Java Beginners
Download a file   Hi, I need a java code to download a file from a website and before downloading it should give me an option to browse and select the location to put the file. Thanks in advance
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
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 file byte reader
Java file byte reader  I am looking for an example program in Java for reading the bytes. More specifically I need java file byte reader example code. Thanks   For complete details read the following tutorials: Java
java file handling
java file handling  program to get values from textbox array and the write them to text files
Java I\O file
Java I\O file  What is the difference between the File and RandomAccessFile classes
Java delete file if exists
Java delete file if exists  Hi, Hi how to delete file if exists? I need example code of java delete file if exists. Thanks   Hi... if tempFile exists File fileTemp = new File(tempFile); if (fileTemp.exists
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java... to write in File of Java Program..., For writing some data in the file we require some class file, objects
Java read binary file
Java read binary file  I want Java read binary file example code... at Reading binary file into byte array in Java. Thanks   Hi, There is many more examples at Java File - Learn how to handle files in Java with Examples
Executale File - Java Beginners
Executale File  Plz tell me how to convert java file into .exe file... the instruction.. Good Luck i don;t know how to create the exe file for java  ... for java but you can create an executable jar file .create a MF file
Advertisements
 

 

 

DMCA.com