RU beehive logo ITEC Department logo
ITEC 120
2007spring
ibarland,
jpittges

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs

lab11a
more list practice
lab11a

Today we will contine the practice-with-loops, as in last Friday's lab.

Work through the examples from this week's lectures. You can download the lecture code.
(how to open .jar files in BlueJ)

Your task: Write a method directoryListing, which (similar to directorySizeTopLevel) is given a directory name. It should return a String which contains the name and size of each file in the directory, and the total size of all those files. (This total size will be the same answer which directoryListing returns.)

For example, on my computer, directoryListing("/Users/ian/120") returns the String

"/Users/ian/120/.DS_Store			6148
/Users/ian/120/check-for-new-html.csh			331
/Users/ian/120/check-for-new-html.csh.~1~			246
/Users/ian/120/class-info.html			10382
/Users/ian/120/class-info.ixml			9137
/Users/ian/120/Exams			1292
/Users/ian/120/Grades			204
/Users/ian/120/Homeworks			3808
/Users/ian/120/hw05-ec.ixml			0
/Users/ian/120/Images			374
/Users/ian/120/index.html			7924
/Users/ian/120/index.ixml			3373
/Users/ian/120/index.ixml.~1~			3734
/Users/ian/120/index.ixml.~2~			3322
/Users/ian/120/index.ixml~			3567
/Users/ian/120/Labs			3400
/Users/ian/120/Lectures			5474
/Users/ian/120/make.ss			561
/Users/ian/120/Makefile			1339
/Users/ian/120/Makefile.~1~			1098
/Users/ian/120/Old			816
/Users/ian/120/syllabus.html			8526
/Users/ian/120/syllabus.ixml			6749
/Users/ian/120/syllabus.ixml.bak~			6764
/Users/ian/120/syllabus.ixml~			6361

Total length: 94930"
(Note that the answer looks like this when called from the Code Pad; if called interactively by right-clicking on a WhilePractice object, the answer window is very long, and it prints newlines as “\n”.)
Windows Filenames: In Linux and MacOS, forward-slashes indicate directories. In Windows, backward-slashes can indicate directories. Remember than if you want to create a Java String which includes back-slashes, you need to use \\ in your code. That is, "H:\\Three\\Directories\\Deep" represents the Windows file “H:\Three\Direcotories\Deep”.

If you finish that, go ahead and make sure you've tried all the programs on the lecture notes. (In particular -- write a method which takes a directory name, and returns a list of all the files which are more than 1MB1.)


11MB = 220 bytes      

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs


©2007, Ian Barland, Radford University
Last modified 2007.Aug.27 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme