0

For a project, I am making a fileserver socket. The socket connection works just fine. However, when the Client connects to the server, the server is supposed to pass a string containing all the filenames within a certain directory (in my case -docs/- directory) to the client. Can someone point me in the direction to some helpful code where the filenames are all retrieved and passed to the client as a single string? Thanks for any help!

1 Answer 1

1

Use File class to get the list of files from the directory. Iterate through the files to form a string (of file names) that you want to pass back to the client.

Try something on these lines-

    final File folder = new File("docs");
    final File[] files = folder.listFiles();
    final StringBuilder filenames = new StringBuilder();
    for(File file : files) {
        filenames.append(file.getName());
        // append separator if required
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Do you have any code snippets or links to similar problem as this? I haven't found any...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.