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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:44:25+00:00 2026-06-08T02:44:25+00:00

I am reading in a file that is being sent though a socket and

  • 0

I am reading in a file that is being sent though a socket and then trying to split it via newlines (\n), when I read in the file I am using a byte[] and I convert the byte array to a string so that I can split it.

public String getUserFileData()
{
    try
    {
        byte[] mybytearray = new byte[1024];
        InputStream is = clientSocket.getInputStream();
        int bytesRead = is.read(mybytearray, 0, mybytearray.length);

        is.close();

        return new String(mybytearray);
    }
    catch(IOException e)
    {

    }

    return "";
}

Here is the code used to attempting to split the String

public void readUserFile(String userData, Log logger)
{
    String[] data;
    String companyName;

    data = userData.split("\n");

    username = data[0];
    password = data[1].toCharArray();
    companyName = data[2];
    quota = Float.parseFloat(data[3]);

    company = new Company();            
    company.readCompanyFile("C:\\Users\\Chris\\Documents\\NetBeansProjects\\ArFile\\ArFile Clients\\" + companyName + "\\"
            + companyName + ".cmp");

    cloudFiles = new CloudFiles();
    cloudFiles.readCloudFiles(this, logger);
}

It causes this error

Exception in thread "AWT-EventQueue-1" java.lang.ArrayIndexOutOfBoundsException
  • 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-08T02:44:27+00:00Added an answer on June 8, 2026 at 2:44 am

    You can use the readLine method in BufferedReader class.

    Wrap the InputStream under InputStreamReader, and wrap it under BufferedReader:

    InputStream is = clientSocket.getInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    

    Please also check the encoding of the stream – you might need to specify the encoding in the constructor of InputStreamReader.

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

Sidebar

Related Questions

I am reading a file that has 10,000 int values and then trying to
I'm reading a text file via CGI in, in perl, and noticing that when
I'm trying to convert a string that I'm reading from a file to lowercase
I am trying to read in a file that has HTML list items with
Flex front-end using AMF to Java back. Trying to read, in real-time, a file
I'm trying to read a binary file that is in the following format: number
I'm reading a .csv file that was created in Excel with the first line
I have a log file that I am reading to a string public static
I am reading in data from a file that has three columns. For example
I am reading data from a file that has, unfortunately, two types of character

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.