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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:52:54+00:00 2026-05-16T04:52:54+00:00

I would like to call the Java class file from compiling the following code:

  • 0

I would like to call the Java class file from compiling the following code:

import java.io.*;

public class hex_to_dec { 
    private BufferedReader bufferedReader;
    private BufferedWriter bufferedWriter;

    public hex_to_dec (String stringPath, String stringPath_dec)
    {
        try
        {
            bufferedReader = new BufferedReader(new FileReader(stringPath));
            bufferedWriter = new BufferedWriter(new FileWriter(stringPath_dec, false));
        } catch (Exception e) {
            System.out.println("Error in opening file." + e);
        }
    }
    public void Parse() 
    {
        try {
            String tempLine;
            int temp;           
            while((tempLine = bufferedReader.readLine()) != null) {
                String[] tempBytes = tempLine.split(" ");
                temp = Integer.valueOf(tempBytes[0], 16);
                tempBytes[0] = String.valueOf((temp));
                temp = Integer.valueOf(tempBytes[2], 16); 
                tempBytes[2] = String.valueOf(((byte) temp));
                temp = Integer.valueOf(tempBytes[3], 16);  
                tempBytes[3] = String.valueOf((temp));
                temp = Integer.valueOf(tempBytes[5], 16);
                tempBytes[5] = String.valueOf(((byte) temp));
                temp = Integer.valueOf(tempBytes[6], 16);
                tempBytes[6] = String.valueOf((temp));
                temp = Integer.valueOf(tempBytes[8], 16);
                tempBytes[8] = String.valueOf(((byte) temp));
                temp = Integer.valueOf(tempBytes[9], 16);
                tempBytes[9] = String.valueOf((temp));
                temp = Integer.valueOf(tempBytes[11], 16);
                tempBytes[11] = String.valueOf(((byte) temp));
                temp = Integer.valueOf(tempBytes[12], 16);
                tempBytes[12] = String.valueOf((temp));
                temp = Integer.valueOf(tempBytes[14], 16);
                tempBytes[14] = String.valueOf(((byte) temp));
                temp = Integer.valueOf(tempBytes[15], 16);
                tempBytes[15] = String.valueOf((temp));
                temp = Integer.valueOf(tempBytes[17], 16);
                tempBytes[17] = String.valueOf(((byte) temp));
                temp = Integer.valueOf(tempBytes[18], 16);
                tempBytes[18] = String.valueOf((temp));
                temp = Integer.valueOf(tempBytes[20], 16);
                tempBytes[20] = String.valueOf(((byte) temp));
                temp = Integer.valueOf(tempBytes[21], 16);
                tempBytes[21] = String.valueOf((temp));
                temp = Integer.valueOf(tempBytes[23], 16);
                tempBytes[23] = String.valueOf(((byte) temp));

                            for (int i = 0; i < tempBytes.length; i++)
                {
                    bufferedWriter.append(tempBytes[i] + " ");
                }
                bufferedWriter.append("\n");                
            }
            bufferedWriter.flush();
        } catch (Exception e) {
            System.err.println("Error:" + e);
        }
    }
    /**
     * @param args
     */
    public static void main(String[] args) { 
        // TODO Auto-generated method stub
        hex_to_dec data = new hex_to_dec(
                "C:\\Documents and Settings\\Admin\\My Documents\\MATLAB\\tests\\rssi_2\\trimmed\\s5_node12",
                "C:\\Documents and Settings\\Admin\\My Documents\\MATLAB\\tests\\rssi_2\\trimmed_dec\\s5_node12"); 
        data.Parse();
    }  
}

However, it requires an argument, and I don’t know how to pass arguments into calling this command cleaning in bash. Also, I would like to be able to parse through a directory to call this function recursively through all the text files under the subdirectories of a selected directory. What’s the easiest way of achieving this?

Thanks in advance! Hope this is not too demanding.

  • 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-16T04:52:55+00:00Added an answer on May 16, 2026 at 4:52 am

    I think you have a couple of steps here, first is to change the main to utilize args. You should check args.length to make sure a source file is specified, for example:

    (warning: untested java from a C programmer)

    public static void main(String[] args)
    {
      if (args.length == 1)
      {
        hex_to_dec data = new hex_to_dec(args[0], args[0] + ".dec");
        data.Parse();
      }
    }
    

    Once the class accepts an argument, you will want to compile it.

    javac hex_to_dec.java
    

    Once it is compiled, you can use a script to recursively handle a directory.

    #!/bin/sh
    find . | xargs -L 1 java hex_to_dec
    

    Note that if your goal is to convert a file of hex numbers to decimal, using java and bash is probably overkill. You could accomplish this using a single shell script like:

    #!/bin/sh
    find . -type f | while read filename
    do
    
      # skip the file if it is already decoded
      if [ "${filename%.dec}" != "${filename}" -o -z "${filename}" ]
      then
        continue
      fi
    
      (
        # read the file, line by line
        cat "${filename}" | while read line
        do
          line=$(
            echo "${line}"                   |
            sed -e "s/[[:space:]]\{1,\}/;/g" | # split the line by spaces
            tr '[:lower:]' '[:upper:]')        # convert lower to uppercase
    
           echo "ibase=16; ${line}"          | # format the line for bc
            bc                               | # convert hex to dec
            tr "\n" " "                        # rejoin the output to a line
    
          echo ""                              # add the new line
        done
      ) > "${filename}.dec"
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 532k
  • Answers 532k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As you mentioned you need to make an object out… May 17, 2026 at 12:10 am
  • Editorial Team
    Editorial Team added an answer This should give you the next occurrence of the 18th… May 17, 2026 at 12:10 am
  • Editorial Team
    Editorial Team added an answer Assuming your assumptions are correct and assuming my memory is… May 17, 2026 at 12:10 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

If you decompile the java.lang.Class class in java from the rt.jar library you will
Often I will send debugging info to my log file from within Java, and
I'm writing my Servlet application and would like to use the following static method
Basically I would like to have some dictionary that is an abstaction over legacy
I'm calling a method from an external library with a (simplified) signature like this:
I have small class called 'Call' and I need to store these calls into
I would like to automatically validate that an XSD Schema is correct. Is there
I am working on a Java project that I want to deliver to my
What I did was create two .java files. One that can compile and run
I'm currently using a separate thread in Java that could potentially be used for

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.