Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package testet.main;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- public class UtilFuncs {
- public static void main(String[] args) {
- System.out.println(checkSender("user1"));
- }
- public static boolean checkSender(String sender) {
- String fileName = "nameList.txt";
- File file = new File(fileName);
- List<String> allowedList = new ArrayList<String>();
- Iterator iter = allowedList.iterator();
- String current;
- int lineCount = 0;
- String[] allowedArray = null;
- boolean isAllowed = false;
- Scanner fileIn;
- Scanner fileIn2;
- try {
- fileIn = new Scanner(file);
- fileIn2 = new Scanner(file);
- while (fileIn.hasNextLine()) {
- System.out.println(fileIn.hasNextLine());
- lineCount++;
- System.out.println(lineCount);
- System.out.println(fileIn.next());
- }
- allowedArray = new String[lineCount];
- for (int i = 0; i < allowedArray.length; i++) {
- current = fileIn2.next();
- allowedArray[i] = current;
- System.out.println(current);
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- System.out.println("allowedArray.length is " + allowedArray.length);
- for (int i = 0; i < allowedArray.length; i++) {
- System.out.println("allowedArray[" + i + "] is " + allowedArray[i]);
- System.out.println("Sender is " + sender);
- System.out.println("Current check is " + allowedArray[i]);
- System.out.println(sender.toString() == allowedArray[i].toString());
- if (allowedArray[i] == sender) {
- isAllowed = true;
- System.out.println("Current check is " + sender + " vs " + allowedArray[i]);
- }
- }
- if (isAllowed == true) {
- return true;
- } else {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment