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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:58:54+00:00 2026-05-21T18:58:54+00:00

I’d like to know how best to make accessable or visible a set of

  • 0

I’d like to know how best to make “accessable” or “visible” a set of File I/O Stream constructors defined in my main routine, to sub-routines.

I found that I cannot use “public”, the compiler issues an “Illegal Expression” error msg.

When I place the file I/O stream and channel constructors in the public class defined for
the entire program “package”. The compiler issues an error stating there’s no FileNotFound or IOException handling declared, so I put on my mainline routine the following:

public static void main(String args[]) throws FileNotFoundException, IOException
 { 
     // and if I then place the File I/O contructors after this: 

                   //Connect to the LU62XC Message File 
    FileOutputStream MesgOut = new FileOutputStream(Mesg_File) ;
    FileChannel MesgChnl  =  MesgOut.getChannel() ;
    ByteBuffer  Mesg_Bufr =  ByteBuffer.allocate(128) ; 

           //Connect to the Request Input File 
    FileInputStream RqstInp = new FileInputStream(Rqst_File) ;  
           //Connect to the Response Output File 
    FileOutputStream RespOut = new FileOutputStream(Resp_File) ;
           //Connect to the Request/Response Log File 
    FileOutputStream LogrOut = new FileOutputStream(Logr_File) ;

I resolve the “no exception handling error”, but now my problem is the sub-routines
that reference the “constructed” file objects essentianlly can’t .. I get a bunch of
“symbol not found” error messages. Again, if I put “public” in front of the file I/O constructors, I get the Illegal expression message.

Is there any way out of this ???

Why the java compiler insists on the program handling file-not-found errors is beyond me.
I mean there’s already the if file_object.exists() method…

IF the file’s NOT there.. the OS will let you know. All ANY application program(OOP or otherwise) does when it comes to I/O of any kind is to make a request to the underlying OS.

  • 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-21T18:58:54+00:00Added an answer on May 21, 2026 at 6:58 pm

    If you want a method to use an object you have as a local variable you can pass its as an argument. This is standard practice in just about every language I can think of. However instead of passing the FileInputStream it is better to pass the file name in camelCase

    // in main
    process(requestFile, responseFile, logFile);
    
    // later
    public static void process(String requestFile, String responseFile, String logFile) throw IOException {
        //Connect to the Request Input File 
        FileInputStream requestIn = new FileInputStream(requestFile);  
        //Connect to the Response Output File 
        FileOutputStream responseOut = new FileOutputStream(responseFile);
        //Connect to the Request/Response Log File 
        FileOutputStream logOut = new FileOutputStream(logFile);
    
        requestIn.close();
        responseOut.close();
        logOut.close();
    }
    

    I get a bunch of “symbol not found” error messages.

    Because a local variable is local to the scope i.e. the method it is in. You can’t use it in another method.

    Again, if I put “public” in front of the file I/O constructors, I get the Illegal expression message.

    Because public fields cannot be defined in a method, they have to be define outside a method, usually at the start of the class.

    Is there any way out of this ???

    Reading a few tutorials http://www.google.com/search?q=java+turorials 11 million results, or working example http://www.google.com/search?q=java+examples 25 million results

    Why the java compiler insists on the program handling file-not-found errors is beyond me. I mean there’s already the If file_object.exists() method… IF the file’s NOT there..the OS will let you know.

    It does let you know by throwing a FileNotFoundException. What do you expect it to do?

    All ANY application program(OOP or otherwise) does when it comes to I/O of any kind is to make a request to the underlying OS.

    And the OS can return an error which you need to be able to handle.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.