Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 537815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:58:00+00:00 2026-05-13T09:58:00+00:00

Okay I’ll try to be direct. I am working on a file sharing application

  • 0

Okay I’ll try to be direct.
I am working on a file sharing application that is based on a common Client/Serer architecture. I also have HandleClient class but that is not particularly important here.

What I wanna do is to allow users to search for a particular file that can be stored in shared folders of other users. For example, 3 users are connected with server and they all have their respective shared folders. One of them wants to do a search for a file named “Madonna” and the application should list all files containing that name and next to that file name there should be an information about user(s) that have/has a wanted file. That information can be either username or IPAddress. Here is the User class, the way it needs to be written (that’s how my superiors wanted it):

import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;

public class User {

    public static String username;
    public static String ipAddress;

    public User(String username, String ipAddress) {

        username = username.toLowerCase();
        System.out.println(username + " " + ipAddress);
    }

    public static void fileList() {

        Scanner userTyping = new Scanner(System.in);
        String fileLocation = userTyping.nextLine();
        File folder = new File(fileLocation);
        File[] files = folder.listFiles();

        ArrayList<String> list = new ArrayList<String>();

        for (int i = 0; i < files.length; i++) {

            list.add(i, files[i].toString().substring(fileLocation.length()));
            System.out.println(list.get(i));

        }

    }

    public static void main(String args[]) {
        System.out.println("Insert the URL of your shared folder");
        User.fileList();

    }


}

This class stores attributes of a particular user (username, IPAddress) and also creates the list of files from the shared folder of that particular user. the list type is ArrayList, that’s how it has to be, again, my superiors told me to.

On the other hand I need another class that is called RequestForFile(String fileName) whose purpose is to look for a certain file within ArrayLists of files from all users that are logged in at the moment of search.

This is how it should look, and this is where I especially need your help cause I get an error and I can’t complete the class.

import java.util.ArrayList;


public class RequestForFile {

    public RequestForFile(String fileName) {

        User user = new User("Slavisha", "84.82.0.1");
        ArrayList<User> listOfUsers = new ArrayList();
        listOfUsers.add(user);

        for (User someUser : listOfUsers) {

            for (String request : User.fileList()) {
                if (request.equals(fileName))
                    System.out.println(someUser + "has that file");
            }

        }

    }

}

The idea is for user to look among the lists of other users and return the user(s) with a location of a wanted file.
GUI aside for now, I will get to it when I fix this problem.
Any help appreciated.
Thanks
I’m here to answer anything regarding this matter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:58:01+00:00Added an answer on May 13, 2026 at 9:58 am

    There are lots of problems here such as:

    I don’t think that this code can compile:

             for (String request : User.fileList()) 
    

    Because fileList() does not return anything. Then there’s the question of why fileList() is static. That means that all User objects are sharing the same list. I guess that you have this becuase you are trying to test your user object from main().

    I think instead you should have coded:

     myUser = new User(...);
     myUser.fileList()
    

    and so fileList could not be static.

    You have now explained your overall problem more clearly, but that reveals some deeper problems.

    Let’s start at the very top. Your request object: I think it represents one request for one user with one file definition. But it needs to go looking in the folders of many users. You add the the requesting user to a list, but what about the others. I think that this means that you need another class responsible for holding all the users.

    Anyway lets have a class called UserManager.

     UserMananger{
    
          ArrayList<User> allTheUsers;
    
           public UserManager() {
    
           }
    
           // methods here for adding and removing users from the list
    
           // plus a method for doing the search
    
           public ArrayList<FileDefinitions> findFile(request) [
                   // build the result
           }
    
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so I can't figure this out. Like a file that I using grep
Okay I have a csv file that gets parsed and displayed. I want to
Okay, I´m working on a website right now that shows information about parts of
Okay, next PHPExcel question. I have an HTML form that users fill out and
Okay, so I'm working on a java server for an Apps backend, it must
okay, i'm setting up a multi-user chat system. i have a messages table, that
Okay, so I'm trying to make a game that uses this algorithm: http://www.codeproject.com/Articles/15573/2D-Polygon-Collision-Detection But
Okay, I am using a custom tab bar (not a tab based app) but
Okay I have created an application where in one of the screens I have
Okay, I have hundreds of .net controls with text attributes that needs to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.