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 8809963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:00:27+00:00 2026-06-14T03:00:27+00:00

I am creating a program to handle a text file different in different methods.

  • 0

I am creating a program to handle a text file different in different methods.
Like opening a filestream in one method, checking if it exists in another method, reading/writeing to the file in a third method and close the filestream in a fourth method.

This does not seem to go very well when I am using the same filestream in a method for checking if the file exists.

Main Code

//Imports the java.io library so the filehandler can read and write to text files.
import java.io.*;

public class filehandler    {

//Variables for the filehandler class.
public String filetohandlename;
public String filetohandleextention;
public String filetohandlefullname = filetohandlename + "." + filetohandleextention;
public String filetohandlepath;
public String filetohandle = filetohandlepath + filetohandlefullname;

//Boolean that is true if the filehandler's "openfilestream"-method has tried to open a filestream.
//Is false as long as none filestreams have been touched.
public boolean filestreamopen = false;

//Declares a variable for the filestream to access text files.
public File filestream;
//End of variable list.

//Called to open a filestream so the server can load properties from text files.
public void openfilestream(File filestream, String filetohandle)    {
    //Open a filestream called "filestream" using the variable "filetohandle"'s value
    //as information about wich file to open the filestream for.
    filestream = new File(filetohandle);
    //Turn the boolean "filestreamopen" to true so next time the server checks it's
    //value, it knows if the filehandler has tried to open a filestream.
    filestreamopen = true;
}

//Boolean that checks if the filestream exists.
public boolean filestreamexists(String filestream)  {
    //Tell the user that a check on the filestream is going on.
    System.out.println("Checking if filestream for \"" + filetohandlefullname + "\" exists...");
    //If the filestream exists...
    if(filestream.exists()) {
        //Tell the user that the filestream exists.
        System.out.println("Filestream for \"" + filetohandlefullname + "\" exists!");
        //Make the boolean's value positive.
        return true;
    }
    //If the filestream does not exist...
    else    {
        //Tell the user that the filestream does not exist.
        System.out.println("Filestream for \"" + filetohandlefullname + "\" does not exist!");
        //Make the boolean's value negative.
        return false;
    }
}

//Called to read files and collect it's information.
public void readfile(String filetohandle)   {
    //Checks if the file that is going to be read is a configuration file.
    if(filetohandleextention == "ini")  {
        //Tell the user that a configuration file is going to be read.
        System.out.println("Extracting information from the configuration file \"" + filetohandle + "\".");
    }
}
}

Problem

The problem lies in checking if the file exists. * if(filestream.exists()) { *
Within the method ” public boolean filestreamexists(String filestream) { “.

The code is simply stored in .java-files in a folder I call “source” and I am using a batch script to compile and run the code: javac -d binary source\*.java.

The error I get when I compile looks like this:

source\filehandler.java:36: error: cannot find symbol
                if(filestream.exists()) {
                             ^
  symbol:   method exists()
  location: variable filestream of type String

NOTE: “filehandler.java” is not the only source code playing a part in my program.
I also have a class called “server”, but it would probably be too long and boring to read if I were to include it in this post, but I got a very important part from the class I feel forced to include:

The server.java file is requesting both the methods “openfilestream” and “filestreamexists”.
This is the code I use when calling “filestreamexists”:

filehandlerclass.filestreamexists(filehandlerclass.filestream);

This gives me another error:

source\server.java:24: error: method filestreamexists in class filehandler canno
t be applied to given types;
                        filehandlerclass.filestreamexists(filehandlerclass.files
tream);
                                        ^
  required: String
  found: File
  reason: actual argument File cannot be converted to String by methodinvocatio
n conversation
  • 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-14T03:00:29+00:00Added an answer on June 14, 2026 at 3:00 am

    Your problem is when you declare filestreamexists(). You declare it like this:

    filestreamexists(String filestream) {
    

    You are passing a string to it not a stream try something like this:

    filestreamexists(File file){
    

    And then you need to change the if to:

    if(file.exists()) {
    

    Also you have some errors in your fileopen, I think this should work better:

    public File file;
    public fileOpen(String fileToOpen) {
        filexists = true;
        try {
            filestream = New File(fileToOpen);
            //File exists
        } catch (IOException e) {
            filexists = false;
            // file doesn't exist
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Bassicly im creating a program that reads information from an xml file into a
I am creating a program to access information on different types of files, I
I am creating a program which has an installer-like interface. Is it better to
I'm creating a program using C# (in ASP.NET environment) that makes an XML file.
if creating a dictionary program. when use copy some text on clipboard it will
Possible Duplicate: Creating, opening and printing a word file from C++ Hi, I need
i am creating a bluetooth based server program in Bluez which basically handles connections
I creating a program which send newsletter with a background image. It works fine
I am creating a program used to connect to a embedded bluetooth device with
I'm creating a program in VB.NET to output multiple images. Some images will have

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.