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.
我的大麻是使用户能够寻找能够储存在其他用户共享的圆顶上的具体档案。 例如,有3个用户与服务器连接,他们都有各自的共享夹。 其中一人希望搜索一个名为“Madonna”的档案,申请应当列出所有载有该名称的档案,然后在档案名称旁边,应当提供拥有/拥有通缉档案的用户信息。 这种信息可以是用户名称,也可以是IPAddress。 这里是用户类别,需要书写的方式(即我的上司如何想):
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();
}
}
这个班级储存特定用户(用户名称、IPAddress)的属性,并编制该特定用户共用组合的档案清单。 名单的类型是ArrayList,这又是我的上司告诉我的。
另一方面,我需要另一个称为“File(String fileName)”的班子,其目的是在ArrayList内部找到一个在搜索时被记录的所有用户的档案。
这就是它应如何看待,这是我特别需要你的帮助,使我错了,我可以完成这一班子。
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.