Results 1 to 4 of 4
Thread: File List shuffle
- 03-12-2011, 08:01 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 2
- Rep Power
- 0
File List shuffle
greetings to this community.
i'm new on java and i'm trying to create a File List, and i used some scripts on google, but the problem is how i can shuffle the filelist????? here is the code:
package com.wowza.wms.example;
import java.io.File;
public class FolderTraversar {
private File fileObject;
public FolderTraversar(String fileObjectname)
{
fileObject = new File(fileObjectname);
}
public void traverse()
{
recursiveTraversal(fileObject);
}
public void recursiveTraversal(File fileObject){
if (fileObject.isDirectory()){
//System.out.println(indent + fileObject.getName());
File allFiles[] = fileObject.listFiles();
for(File aFile : allFiles){
recursiveTraversal(aFile);
}
}else if (fileObject.isFile()){
//System.out.println(indent + " " + fileObject.getName());
System.out.println(fileObject.getAbsoluteFile());
}
}
}
- 03-12-2011, 08:52 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
the problem is how i can shuffle the filelist?
What file list?
In the code you obtain an array allFiles of the children of the File currently being visited. Is this what you are trying to shuffle? If so, why?
-------------------------
When posting code use the code tags: you put [code] at the start of the code and [/code] at the end. That way the indenting is preserved and it is easier to read.
- 03-12-2011, 10:23 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 2
- Rep Power
- 0
i'm trying to shuffle the files for a running playlist, and i don't want the same sort.
yes it's what i want
- 03-12-2011, 10:59 PM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Use Arrays.asList() to obtain a list. Then use Collections.shuffle() on the list.
Java Code:import java.util.Arrays; import java.util.Collections; import java.util.List; public class ArrayShuffleEg { public static void main(String[] args) { String[] data = {"one", "two", "three", "four", "five"}; List<String> list = Arrays.asList(data); Collections.shuffle(list); for(String str :list) { System.out.println(str); } } }
Similar Threads
-
Deck Shuffle
By Cragsterboy in forum New To JavaReplies: 1Last Post: 12-13-2010, 04:23 PM -
Shuffle Group Method
By xelo in forum New To JavaReplies: 6Last Post: 01-05-2009, 07:41 PM -
2D Array Random Shuffle
By Nuluvius in forum New To JavaReplies: 8Last Post: 11-23-2008, 06:15 PM -
How do I shuffle an arraylist?
By frasifrasi in forum New To JavaReplies: 2Last Post: 07-16-2008, 11:29 PM -
How to Shuffle a particular String
By Java Tip in forum java.langReplies: 0Last Post: 04-06-2008, 07:38 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks