Java File 1 Answer(s) 3 years and 8 months ago
Posted in : Java Beginners
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 Pages:
File File How to find all files in our local computer using java
FILE
;Java Read content of File
import java.io.*;
public class Appliance {
public...FILE There is a file named Name.txt that contains information related to appliances.I want to read the contents of this file and I used the code
file
file hi i want read special line of file. what am i doing ?
I write a code but is false in this programm i want make tree with java but i should read data from file. please help me!
void maketree(BtNode root,int i) throws
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
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 Javafile class What is the purpose of the File class
Convert Class File to .java File - Java Beginners
Convert Class File to .java File Sir, How To Convert .class file to .javaFile.
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
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
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 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
java file handling javafile 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
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
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
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
Execute .dll file in java?
Execute .dll file in java? please anybody give me solution for executing .dll files in java
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
File Transfer File Transfer How to create a file in server side using java swing
Read from file java
Read from file java How to Read from filejava? 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
jar file
jar file how to create a jar file in java
Java I\O file Java I\O file What is the difference between the File and RandomAccessFile classes
java file handling javafile handling program to get values from textbox array and the write them to text files
Java file byte reader Javafile byte reader I am looking for an example program in Java for reading the bytes. More specifically I need javafile byte reader example code.
Thanks
For complete details read the following tutorials:
Java
on file system
on file system how to maintains record in a file using java and how to create objects to each record.
Hi,
Please read Java Write file tutorial.
Regards
Deepak
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 JavaFile - Learn how to handle files in Java with Examples
Executale File - Java Beginners
Executale File Plz tell me how to convert javafile 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
jar file - Java Beginners
an application packaged as a JAR file (requires the Main-class manifest header)java -jar...jar file jar file When creating a jar file it requires a manifest file. what is the manifest file, and how to create it. And tell me more about
IO File - Java Beginners
IO File Write a java program which will read an input file & will produce an output file which will extract errors & warnings.
It shall exclude... from the log file.
This is the task assigned to me..Please help me
Java upload file to ftp Java upload file to ftp Hi,
How to uploaded file to a ftp server in Java?
Thanks
Hi,
It's very easy to write a program in Java....
View complete example at FTP File Upload in Java
Thanks
How to Write to file in Java?
How to Write to file in Java? How to Write to file in Java Program?
Hi,
For writing a file in Java, we need some classes from Java.IO package. Mostly we define two types of classes in javafile i.e. FileWriter
JAR FILE
and applications.
The Java Archive (JAR) file format enables to bundle multiple files into a single archive file.
For more information, visit the following...JAR FILE WHAT IS JAR FILE,EXPLAIN IN DETAIL?
A JAR file
File handlig File handlig File hyandling
Hi Please the click on the following link
Javafile Handling
And read the Articles given in it
Hi Please the click on the following link
Javafile Handling
And read
xml file creation in java
xml file creation in java how to create xml file in java so that input should not be given from keyboard. and that file should be stored.
Please visit the following links:
http://www.roseindia.net/tutorial/java/xml
java file handling javafile handling Hi friends,
My situation is i have file named "sample.conf" which contains more IP Adressess.Eg: the file contains "IP=255.255.255.255" at some lines in the file. what i need to do is. i need to search
copy file - Java Beginners File("C:\\Answers\\Master.txt"),new File("c:\\java\\Master.txt...copy file i want to copy file from one folder to another
 ... CopyFile{
public void copy(File src, File dst) throws IOException
jar file
jar file how to run a javafile by making it a desktop icon i need complete procedur ..through cmd
Playing mp3 file in Java...
Playing mp3 file in Java... I created frame with play and stop buttons and added separate ActionListener to those buttons but i can't stop the music while playing
Creating dynamic jsp file in java file to include another jsp file
Creating dynamic jsp file in javafile to include another jsp file I am able to create jsp file in java that includes ;
table
tr
td
and img tags.....
Need to include jsp file in the same content.
The below code doesn't help me
file handling - Java Beginners
manner.
now write a progam in java and create another file which is having the amount required to purchase each item and at last read the newly created file...file handling assume two files are there- 1. with the quanity of he
Java Jar File - Java Beginners Java Jar File What is a Java JAR file ..and how can i open a .jar file in Java? Just create a Jar file and Double click on it, it will automatically runs main method in that Jar : to create Project as JAR
File - Java Beginners
. Here it is:
Write a program to create a file named "numbers.dat". Then create... by a comma. After the file has been created, close and reopen the file and display... number integers from 1 to 100, separated by a comma to the end of the file. Reopen