Am a new member from Kenya. Newbie in java but has background in sql, asp.net and ms access.Wanna share and learn Java from you guys

Recommended Answers

All 6 Replies

Welcome!

Hi...Welcome to Daniweb Friend :)

thanks guys...we'll get working.

Nice to have you here!

Hi all,
I have built some code that prints out directory files and non-diectory files. I want to get some help in indenting my code further to achieve level 5 indentation since now its up to2. Any ideas please. Below is the code.

package com.jjpeople.Ronald.javafundamentals.FileIteration;


/**
*
*
*/
import java.io.*;
import java.io.File;
public class FileIterator
{
public void printContents(File folder,Boolean displayFiles,Boolean isSubDir)
{
String totalspace="";
String dirFilecount="";
String dirspace ="";
String filespace="";
DirUtils dirUtil=new DirUtils();
File[] directorys = folder.listFiles();
if (isSubDir)
{
dirspace ="   ";
}
for(int i=0;i<directorys.length;i++)
{


if (dirUtil.isDirectory(directorys))
{
totalspace=""+directorys.getTotalSpace();
dirFilecount=""+directorys.list().length;
System.out.println(dirspace+directorys.getName()+"(File count= "+ dirFilecount+" size="+totalspace+")");
//System.out.println("-------------------------------------");
printContents(directorys,displayFiles,true);
// dirspace=dirspace+ " ";
}
else
{
if (displayFiles==true)
{
System.out.println(dirspace + filespace+directorys.getName());
}
}
}
}
public static void main(String[]args) throws IOException
{
String x;
// TODO code application logic here
File rootFolder = new File("C:/javacode");
FileIterator fi = new FileIterator();
System.out.println("Do you want the directories and files to be written out or just directories? (Y or N) ");
BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
x=in.readLine();


if ((x.equalsIgnoreCase("N")) || (x.equalsIgnoreCase("n")))
{
fi.printContents(rootFolder,false,false);
}
else if ((x.equalsIgnoreCase("Y")) || (x.equalsIgnoreCase("y")))
{
fi.printContents(rootFolder,true,false);
}
else
{
System.out.println("sorry you entered a wrong value");
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/


package com.jjpeople.Ronald.javafundamentals.FileIteration;


/**
*
* @author Ronald Ojino
*/
import java.io.File;
import java.io.*;
public class DirUtils implements FileFilter
{
public boolean accept(File file)
{
return file.isFile();
}
public static boolean isDirectory(File file)
{
return file.isDirectory();
}
public static boolean isNotDirectory(File file)
{
return  !file.isDirectory();
}
}



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/


package com.jjpeople.Ronald.javafundamentals.FileIteration;


/**
*
* @author Ronald Ojino
*/
import java.io.File;
import java.io.*;
public class DirUtils implements FileFilter
{
public boolean accept(File file)
{
return file.isFile();
}
public static boolean isDirectory(File file)
{
return file.isDirectory();
}
public static boolean isNotDirectory(File file)
{
return  !file.isDirectory();
}
}

Welcome! I really like it here, and I am sure you will too!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.