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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:06:35+00:00 2026-05-29T21:06:35+00:00

The program i am working on looks at various ASCII text files and does

  • 0

The program i am working on looks at various ASCII text files and does some processing. In order to know how to handle things, it needs to know whether file

- IS_EMPTY         // done
- IS_JSON          // done via parsing, using gson
- IS_XML           // done via parsing, using dom4j
- IS_PROPERTIES    
- IS_SCRIPT

I wonder if there is an effective way to determine whether file is of type properties without reading each line to see if it contains Key=Value pair?

Additionally, is there an effective way to determine whether file is a shell script?

Are there any parsers available to check this?

  • 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-29T21:06:38+00:00Added an answer on May 29, 2026 at 9:06 pm

    If a requirement of your program is that the input files be well-formatted and not mixed-type, then I would recommend replacing your JSON and XML impls with the following:

    1. JSON – simply look for an opening ‘{‘ as one of the first chars in the file; this is an invalid format for any other files (except maybe script depending on your format). If you find ‘{‘ as the first char, its a JSON. This saves on processing the entire file with GSON.

    2. XML – look for file header; well-formed XML files cannot even have space before this header; it must appear immediately. Again, no reason to try and ingest the entire thing just to catch an exception.

    3. PROPERTIES – in the same vein, I would check the first line and make sure it has =\n format. If they do, you are good to go.

    4. SCRIPT – I am not sure the format of your scripting language, but you get the idea.

    All told, doing cheap/quick checks if your requirements are well-defined is the way to go here. If you require a JSON file to be all JSON and the first char you encounter reading the file is ‘{‘ then I’d say that is a JSON file and not EMPTY, XML or PROPERTIES (again, excluding SCRIPT because I don’t know the format).

    Then you can rewind the input stream and give it to your parsing library to read (this is where PushbackInputStreams can come handy)

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

Sidebar

Related Questions

I've been working for some months on a program for processing some data, and
I'm working with Ripper sexp expressions, it looks like this: [:program, [[:class, [:const_ref, [:@const,
I'm new to Java and working on a basic program that looks through an
I am working on a program that needs to check the existence of a
for some reason my server that uses socket.io is not working properly. The program
A program i am working on deals with processing file content. Right now i
Does anyone have a working setup for hunspell and Emacs ? Simply setting ispell-program-name
Background: I am writing a C++ program working with large amounts of geodata, and
how can i make java program working with multiple languages (frensh, english , arabic
Having successfully gotten a sample program working, I'm now starting to do Real Work

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.