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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:40:07+00:00 2026-06-09T02:40:07+00:00

I had some problems printing out a student store with which I used an

  • 0

I had some problems printing out a student store with which I used an ArrayList. I then made a static array to hold these different students and now I’m trying to find out what method I can use to write them. Here is my code:

MainApp
import java.io.RandomAccessFile;



    public class MainApp
    {

        public static void main(String[] args) throws Exception 
        {
            new MainApp().start();

        }
        public void start()throws Exception 
        {
            StudentStore details = new StudentStore();
            Student a = new Student("Becky O'Brien", "DKIT26", "0876126944", "bexo@hotmail.com");
            Student b = new Student("Fabio Borini", "DKIT28", "0876136944", "fabioborini@gmail.com");
            Student c = new Student("Gaston Ramirez", "DKIT29", "0419834501", "gramirez@webmail.com");
            Student d = new Student("Luis Suarez", "DKIT7", "0868989878", "luissuarez@yahoo.com");
            Student e = new Student("Andy Carroll", "DKIT9", "0853456788", "carroll123@hotmail.com");
            details.add(a);
            details.add(b);
            details.add(c);
            details.add(d);
            details.add(e);
            //details.print();


            RandomAccessFile file = new RandomAccessFile("ContactDetails.txt","rw");

            Student[] students = {a,b,c,d,e};
            for (int i = 0;i < students.length;i++)
            {
                file.writeByte(students[i]);
            }
            file.close();


         }


     }

The line file.writeByte(students[i]); is incorrect and I can’t find a method to suit this. The error reads the method writeByte(int) in the type RandomAccessFile is not applicable for the arguments (Student). This is obviously because writeBytes method does not take the type student.

  • 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-06-09T02:40:10+00:00Added an answer on June 9, 2026 at 2:40 am

    Strings have a very easy way to convert into bytes. They have a getBytes() method that would work well. You can get a string representation of a student by overloading the toString() method. So your call would look a lot like

    file.writeByte(students[i].toString().getBytes( "UTF-8" ));
    

    edit:

    Forgot getBytes() returns an array of bytes. This should work:

    byte[] bytes = students[i].toString().getBytes();
    for(byte byteWrite : bytes){
        file.writeByte(byteWrite);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had some problems with my subversion server and i had to restore it
I've had some problems with a Django application after I deployed it. I use
I've recently moved to Java, but I've had some problems with variable aliasing. I've
I've had some problems using timeit() as an accurate benchmark when comparing longer (>
I began taking up Heroku again, but have had some problems trying to get
I had some problems with my server so i built my portlets and tested
I had some problems when I tried to create a loop in asm. So
I'm starting developing app in WindowsPhone, and had some problems. I trying to add
I had this problem some time ago and I gave up but lately it
I have a little problem. I had some JComboBox to a JDialog but they

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.