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

Related Questions

I would like to call the following java method from scala: protected final FilterKeyBindingBuilder
I created the following class located in the MainJPrint.java file import com.XXXXX.pdfPrint.PDFPrint; public class
I would like to call an R script from Java. I have done google
I would like to call a Python script from within a Bash while loop.
I have a JavaFX app with a some code like this... public class MainListener
I call a class which is located somewhere in a jar file (using java
I would like to call my Selenium tests, written in Java ( @Test annotated)
I would like to implement method overloading in the Java web service class as
I would like to call JavaScript function many time . I have tried like
I would like to call a stored procedure (Oracle). As I my procedure calls

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.