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

  • Home
  • SEARCH
  • 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 8780711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:07:35+00:00 2026-06-13T20:07:35+00:00

I have a Java program that searches through your cookies files and then saves

  • 0

I have a Java program that searches through your cookies files and then saves each file into an array. I then try to search through each of those files for a certain string, however when I try to search the files I KNOW exist, java tells me that they don’t. Any ideas?

Here is my code so far:

   import java.io.*;
   import java.util.*;

   public class CheckCookie 
   {
      static String[] textFiles = new String[100];
        static String userName = "";

      public static void findCookies()
      {

         String path = "pathtocookies"; 

         String files;
         File folder = new File(path);
         File[] listOfFiles = folder.listFiles(); 

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

            if (listOfFiles[i].isFile()) 
            {
               files = listOfFiles[i].getName();
               if (files.endsWith(".txt") || files.endsWith(".TXT"))
               {
                  textFiles[i] = files;
               }
            }
         }
      }

      public static boolean searchCookies()
      {
         for(int j = 0; j < textFiles.length; j++) {
                String path2 = "pathtocookies"+textFiles[j];
            File file = new File(path2);

            try {
               Scanner scan = new Scanner(file);
               while (scan.hasNext()) {
                  String line = scan.nextLine();
                  if(line.contains("ineligible_age")) { 
                            System.out.println("A cookie for ineligible age was set.");             
                            return true;
                  }
               }

            } 
               catch(FileNotFoundException e) { 
               System.out.println("File was not found.");
                    return false;
               }
         }
            System.out.println("A cookie for ineligible age was not set.");
         return false;
      }

      public static void main(String[] args) 
      {
         findCookies();
            searchCookies();
            System.out.println();
            System.out.println("Finished searching for cookies. Yum.");
      }

   }

Actual path:

C:/Users/lucas.brandt/AppData/Roaming/Microsoft/Windows/Cookies
  • 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-06-13T20:07:36+00:00Added an answer on June 13, 2026 at 8:07 pm

    Use a List, instead of an array to store the textFiles.

    Imagine a directory with 2 files. The first is “abc.doc”, the second “itsme.txt”

    Your textFiles array will look like this:

    • textFiles[0]: null
    • textFiles[1]: “itsme.txt”

    So you try to access “pathtocookies” + “null” which will fail, you go to the catch and return out of the function.

    Further hints:

    • Return the list from the first function, use it as an argument for the second function
    • Use a debugger or “debug” print statements to debug your code to see whats happening

    More hints depends on the actual use case.

    –tb

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small java program that searches the contents of all *.txt files
I have a Java program that is launched by a batch file with a
I have a Java program that opens a file using the RandomAccessFile class. I'd
I have written a Java program on my computer that searches on the net
I have a java program that is supposed to run a bat file, and
I have a static java program that searches a folder for the most recently
I have a Java program that loads thirdparty class files (classes I did not
I have a Java program that runs on Linux and telnets into a remote
I have a java program that performs 5 different tasks. When I run the
I have a java program that is running in the background(Windows). I would like

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.