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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:37:12+00:00 2026-05-21T14:37:12+00:00

I’m involved in a project where we hide information in an mp3 file by

  • 0

I’m involved in a project where we hide information in an mp3 file by modifying bytes at a specified position. I found code online which lets me write and read bytes and I was playing with it to read the first 10 bytes in a mp3 file.

However there’s a problem, it goes up until the 4th byte, after that the program ends. Or in other words, in my for cycle it only goes until i=4.

This is the output I get.

Read 0th character of file: I
Read 1th character of file: D
Read 2th character of file: 3
Read 3th character of file: 
Read 4th character of file: 
Process completed.

The cycle somehow ends there, if you notice the program should end with the system.out message that goes “end of program” but not even that comes out. The code’s below. I’ve tried with several mp3 files and the results the same.

What could be the problem? why does my program ends without even giving me an error message?

import java.io.File;
import java.io.RandomAccessFile;
import java.io.IOException;

public class Edit {

private static void doAccess() { try { //Reads mp3 file named a.mp3 File file = new File("a.mp3"); RandomAccessFile raf = new RandomAccessFile(file, "rw"); //In this part I try to read the first 10 bytes in the file byte ch; for (long i = 0; i < 10 ; i++) { raf.seek(i); //position ourselves at position i ch = raf.readByte(); //read the byte at position i System.out.println("Read "+ i + "th character of file: " + (char)ch); //print the byte at that position //repeat till position 10 } System.out.println("End of program"); raf.close(); } catch (IOException e) { System.out.println("IOException:"); e.printStackTrace(); } } public static void main(String[] args) { doAccess(); } }

Thanks in advance!

  • 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-21T14:37:13+00:00Added an answer on May 21, 2026 at 2:37 pm

    I just tried your code and it works for me. The problem is with the way your IDE handles '\0' characters (the 4th byte is '\0'). In order to see the real output change the print statement (inside the loop) to:

    System.out.println("Read " + i + "th character of file: " + ch);
    

    (that is: omit char (char) casting). You will then get this output:

    Read 0th character of file: 73
    Read 1th character of file: 68
    Read 2th character of file: 51
    Read 3th character of file: 3
    Read 4th character of file: 0
    Read 5th character of file: 0
    Read 6th character of file: 0
    Read 7th character of file: 0
    Read 8th character of file: 15
    Read 9th character of file: 118
    End of program
    

    Other than that I suggest the following:

    • Consider using a pre-made library for retriving/writing MP3 meta-data. This is far better than implementing this logic from scratch.
    • You don’t need to seek() inside the loop. when you open the file you’re at position 0, and every readByte() advances the position by 1.
    • The code will be more readable if you move the definition of the ch variable inside the loop. If you only use it inside the loop there’s no reason to define it outside.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

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 am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words

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.