JavaTpoint offers too many high quality services. Mail us on [email protected] , to get more information about given services. Please mail your requirement at [email protected] Duration: 1 week to 2 week. Java Serialization Java transient keyword. IOException; import java. Next Topic java. Reinforcement Learning. R Programming. React Native. Python Design Patterns. Python Pillow. Python Turtle. Verbal Ability.
Interview Questions. Company Questions. Artificial Intelligence. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New. Most popular in Java. More related articles in Java. We use cookies to ensure you have the best browsing experience on our website. It's always best to try to do something first before asking here, and showing your attempt with your question. In the very least, this will result in a much better and much more specific question.
I'd also recommend that you remove any code not relevant to the problem at hand and any additional code needed to make your posted code runnable and compilable, and nothing more. Basically, you want to get a list of the files in the directory, then use a random number generator to select one of them. You sorta have that setup above it's a little unclear why you construct fileArray , but you don't show how you use it, or explain what's wrong with what you have already.
Any issue you might be facing? Add a comment. Active Oldest Votes. Create an array of the files within the given directory using File. Select a file based on a random index from this array. That can be done with an instance of the Random class, using Random. XenoRo 5, 4 4 gold badges 40 40 silver badges 55 55 bronze badges.
Yes this works, however it prints out the full path name I just want the name of the file how would i do that? ChrisEthanFox That has nothing to do with the code passion provided here; that's the way you're printing. But as for the answer, that would be done with file.
Passion No problem! Everyone starts somewhere and I'm happy to nudge you in the right direction and help you grow! XenoRo XenoRo 5, 4 4 gold badges 40 40 silver badges 55 55 bronze badges.
0コメント