0

I want to list a names of the files and put them into String array. To list a names of the files I'm using this code:

File dir = new File("/sdcard/Images/1124/"); File[] files = dir.listFiles(); for (int i = 0; i < files.length; ++i){ Log.i(String.valueOf(files[i].getName()),"files"); } 

I want to get something like that but with automatic values of files[i]:

String[] files = new String[] { "/sdcard/Images/1124/pic.jpg","/sdcard/Images/1124/pic2.jpg" }; 

So how can I do it?

Thanks

1
  • Doesn't your code work? What ìs the output? Commented Jun 20, 2012 at 12:19

1 Answer 1

5

Have you tried?

String[] fileArray; File dir = new File("/sdcard/Images/1124/"); File[] files = dir.listFiles(); fileArray = new String[files.length]; for (int i = 0; i < files.length; ++i){ fileArray[i] = files[i].getName(); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.