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

  • Home
  • SEARCH
  • 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 8390605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:02:20+00:00 2026-06-09T19:02:20+00:00

What I am trying to achieve is read data off an Excel Sheet (saved

  • 0

What I am trying to achieve is read data off an Excel Sheet (saved in Txt, tab delimited), row by row and each individual column is different data that I want to store in an array.

I tried different ways.. I even downloaded CSVReader class off the internet and it didnt work.
At least this time its reading real Characters and not jiberish.

The version I have now is uses bufferedReader and String Tokenizer.
But it’s not reading properly.

Here’s the code:

     import java.io.BufferedReader;
     import java.io.BufferedWriter;
     import java.io.File;
     import java.io.FileNotFoundException;
     import java.io.FileReader;
     import java.io.FileWriter;
     import java.io.IOException;
     import java.util.StringTokenizer;

     import com.csvreader.CsvReader;

     import au.com.bytecode.opencsv.CSVReader;


     public class excelToText{
     public static void main(String[] args) throws IOException {

    try
    {

        //csv file containing data
          BufferedReader CSVFile = new BufferedReader(new          FileReader("C:/Users/nhajjar/workspace/MB/src/yoyo.txt"));


          // Read first line.
          String dataRow; 
          int lineNumber = 0; 


          while ((dataRow = CSVFile.readLine() )!= null)
          {
                String [] dataArray;
                lineNumber++; 



                String delimiter = "\t";
                /* given string will be split by the argument delimiter provided. */
                dataArray = dataRow.split(delimiter);
                /* print substrings */

// for(int i =0; i < dataArray.length ; i++)
// System.out.println(dataArray[i]);

                String PrinterName = dataArray[0];
                String Model = dataArray[1];
                String IP = dataArray[2];
                String Location = dataArray[3];
                String Department = dataArray[4];
                String PrimServer = dataArray[5];
                String SecServer = dataArray[6];
                String ShareName = dataArray[7];
                String GroupNamePrefix = dataArray[8];
                String GroupNameSuffix = dataArray[9];
                String GroupNameFinal = dataArray[10];
                String WSPPrefix = dataArray[11];
                String WSPFull = dataArray[12];
                String PrimWSP = dataArray[13];
                String SecWSP = dataArray[14];

              System.out.println("PrinterName is : " + PrinterName);
                System.out.println("Model is : " + Model);
                System.out.println("IP is : " + IP);
                System.out.println("Location is : " + Location);
                System.out.println("Department is : " + Department);
                System.out.println("PrimServer is : " + PrimServer);
                System.out.println("SecServer is : " + SecServer);
                System.out.println("ShareName is : " + ShareName);
                System.out.println("GroupNamePrefix is : " + GroupNamePrefix);
                System.out.println("GroupNameSuffix is : " + GroupNameSuffix);
                System.out.println("GroupNameFinal is : " + GroupNameFinal);
                System.out.println("WSPPrefix is : " + WSPPrefix);
                System.out.println("WSPFull is : " + WSPFull);
                System.out.println("PrimWSP is : " + PrimWSP);
                System.out.println("PrimWSP is : " + PrimWSP);
                System.out.println("SecWSP is : " + SecWSP);



                /*//writing file for ones that were not sent out. 
                  File file = new File("write.txt");
                  BufferedWriter output = new BufferedWriter(new FileWriter(file));
                  */

            }




            CSVFile.close();

        }   catch (FileNotFoundException e) {
            e.printStackTrace();
        }   catch (IOException e) {
            e.printStackTrace();
        }   catch(Exception e)          {
          System.out.println("Exception while reading/writing csv file: " + e);                   
        }// end Exceptions 

  }// end try block 
     }

input is :

    Printer name    Model   IP  Location    Department  Primary Server  Secondary Server    Share Name
    Boundary Sprinter Techs Lexmark E360dn      Boundary    Sprinter    s173m928site    s173mho1site    928-Sprinter-techs-L-E360dn
    Boundary Sprinter Xerox 7232    Xerox WorkCentre 7232       Boundary    Sprinter    s173m928site    s173mho1site    928-Sprinter-WC7232
    Boundry Parts   HP LaserJet P2055dn     Boundary    Parts   s173m928site    s173mho1site    928-Parts-LJ-P2055dn
    Boundry Sales   HP Color LaserJet CP4005        Boundary    Sales   s173m928site    s173mho1site    928-Sales-Main-CP4005
    Boundry Techs East  HP LaserJet P3015       Boundary    Techs East  s173m928site    s173mho1site    928-Techs-east-LJ-P3015
    Boundry Techs West  Lexmark E352dn      Boundary    Techs West  s173m928site    s173mho1site    928-Techs-west-L-E352dn
    Concord     Lexmark E360dn      Concord         s173mho1site    
    Dundas Parts    Xerox WorkCentre 7232       Dundas  Parts   s173m910site    s173mho1site    910-Parts-WC-7232
    Dundas Preowned Xerox WorkCentre 7425       Dundas  Preowned    s173m910site    s173mho1site    910-PreOwned-WC-7425
    Dundas Sales 2nd Floor  HP Color LaserJet CP4025        Dundas  Sales   s173m910site    s173mho1site    910-Sales-2nd-CP4025
    Dundas Sales Main Floor HP Color LaserJet CP4025        Dundas  Sales   s173m910site    s173mho1site    910-Sales-Main-CP4025


output im getting is : 


PrinterName is : Printer name 
Model is : Model
IP is : IP
Location is : Location
Department is : Department
PrimServer is : Primary Server 
SecServer is : Secondary Server
ShareName is : Share Name
GroupNamePrefix is : Group Name Prefix
GroupNameSuffix is : Group Name Suffix
GroupNameFinal is : Group Name Final
WSPPrefix is : WSP Prefix
WSPFull is : WSP Full
PrimWSP is : Primary WSP
PrimWSP is : Primary WSP
SecWSP is : Secondary WSP


PrinterName is : Boundary Sprinter Techs
Model is : Lexmark E360dn
IP is : 53.254.177.138
Location is : Boundary
Department is : Sprinter
PrimServer is : s173m928site
SecServer is : s173mho1site
ShareName is : 928-Sprinter-techs-L-E360dn
GroupNamePrefix is : D173_PRINTER-
GroupNameSuffix is : 928-Sprinter-techs-L-E360dn
GroupNameFinal is : D173_PRINTER-928-Sprinter-techs-L-E360dn
WSPPrefix is : #;\D173\_GLOBALRESOURCES\GROUPS\Printers\
WSPFull is : #;\D173\_GLOBALRESOURCES\GROUPS\Printers\D173_PRINTER-928-Sprinter-techs-L-E360dn.wsp;D173_PRINTER-928-Sprinter-techs-L-E360dn
PrimWSP is : >;%;\\s173m928site.cambc.corpintra.net\928-Sprinter-techs-L-E360dn
PrimWSP is : >;%;\\s173m928site.cambc.corpintra.net\928-Sprinter-techs-L-E360dn
SecWSP is : ;>;%;\\s173mho1site.cambc.corpintra.net\928-Sprinter-techs-L-E360dn


PrinterName is : Boundary Sprinter Xerox 7232
Model is : Xerox WorkCentre 7232
IP is : 53.254.177.136
Location is : Boundary
Department is : Sprinter
PrimServer is : s173m928site
SecServer is : s173mho1site
ShareName is : 928-Sprinter-WC7232
GroupNamePrefix is : D173_PRINTER-
GroupNameSuffix is : 928-Sprinter-WC7232
GroupNameFinal is : D173_PRINTER-928-Sprinter-WC7232
WSPPrefix is : #;\D173\_GLOBALRESOURCES\GROUPS\Printers\
WSPFull is : #;\D173\_GLOBALRESOURCES\GROUPS\Printers\D173_PRINTER-928-Sprinter-WC7232.wsp;D173_PRINTER-928-Sprinter-WC7232
PrimWSP is : >;%;\\s173m928site.cambc.corpintra.net\928-Sprinter-WC7232
PrimWSP is : >;%;\\s173m928site.cambc.corpintra.net\928-Sprinter-WC7232
SecWSP is : ;>;%;\\s173mho1site.cambc.corpintra.net\928-Sprinter-WC7232


PrinterName is : Boundry Parts
Model is : HP LaserJet P2055dn
IP is : 53.254.193.222
Location is : Boundary
Department is : Parts
PrimServer is : s173m928site
SecServer is : s173mho1site
ShareName is : 928-Parts-LJ-P2055dn
GroupNamePrefix is : D173_PRINTER-
GroupNameSuffix is : 928-Parts-LJ-P2055dn
GroupNameFinal is : D173_PRINTER-928-Parts-LJ-P2055dn
WSPPrefix is : #;\D173\_GLOBALRESOURCES\GROUPS\Printers\
WSPFull is : #;\D173\_GLOBALRESOURCES\GROUPS\Printers\D173_PRINTER-928-Parts-LJ-P2055dn.wsp;D173_PRINTER-928-Parts-LJ-P2055dn
PrimWSP is : >;%;\\s173m928site.cambc.corpintra.net\928-Parts-LJ-P2055dn
PrimWSP is : >;%;\\s173m928site.cambc.corpintra.net\928-Parts-LJ-P2055dn
SecWSP is : ;>;%;\\s173mho1site.cambc.corpintra.net\928-Parts-LJ-P2055dn


PrinterName is : Boundry Sales
Model is : HP Color LaserJet CP4005
IP is : 53.254.193.117
Location is : Boundary
Department is : Sales
PrimServer is : s173m928site
SecServer is : s173mho1site
ShareName is : 928-Sales-Main-CP4005
GroupNamePrefix is : D173_PRINTER-
GroupNameSuffix is : 928-Sales-Main-CP4005
GroupNameFinal is : D173_PRINTER-928-Sales-Main-CP4005
WSPPrefix is : #;\D173\_GLOBALRESOURCES\GROUPS\Printers\
WSPFull is : #;\D173\_GLOBALRESOURCES\GROUPS\Printers\D173_PRINTER-928-Sales-Main-CP4005.wsp;D173_PRINTER-928-Sales-Main-CP4005
PrimWSP is : >;%;\\s173m928site.cambc.corpintra.net\928-Sales-Main-CP4005
PrimWSP is : >;%;\\s173m928site.cambc.corpintra.net\928-Sales-Main-CP4005
SecWSP is : ;>;%;\\s173mho1site.cambc.corpintra.net\928-Sales-Main-CP4005


PrinterName is : Boundry Techs East
Model is : HP LaserJet P3015
IP is : 53.254.193.220
Location is : Boundary
Department is : Techs East
PrimServer is : s173m928site
SecServer is : s173mho1site
ShareName is : 928-Techs-east-LJ-P3015
GroupNamePrefix is : D173_PRINTER-
GroupNameSuffix is : 928-Techs-east-LJ-P3015
GroupNameFinal is : D173_PRINTER-928-Techs-east-LJ-P3015
WSPPrefix is : #;\D173\_GLOBALRESOURCES\GROUPS\Printers\
WSPFull is : #;\D173\_GLOBALRESOURCES\GROUPS\Printers\D173_PRINTER-928-Techs-east-LJ-P3015.wsp;D173_PRINTER-928-Techs-east-LJ-P3015
PrimWSP is : >;%;\\s173m928site.cambc.corpintra.net\928-Techs-east-LJ-P3015
PrimWSP is : >;%;\\s173m928site.cambc.corpintra.net\928-Techs-east-LJ-P3015
SecWSP is : ;>;%;\\s173mho1site.cambc.corpintra.net\928-Techs-east-LJ-P3015


PrinterName is : Boundry Techs West
Model is : Lexmark E352dn
IP is : 53.254.193.221
Location is : Boundary
Department is : Techs West
PrimServer is : s173m928site
SecServer is : s173mho1site
ShareName is : 928-Techs-west-L-E352dn
GroupNamePrefix is : D173_PRINTER-
GroupNameSuffix is : 928-Techs-west-L-E352dn
GroupNameFinal is : D173_PRINTER-928-Techs-west-L-E352dn
WSPPrefix is : #;\D173\_GLOBALRESOURCES\GROUPS\Printers\
WSPFull is : #;\D173\_GLOBALRESOURCES\GROUPS\Printers\D173_PRINTER-928-Techs-west-L-E352dn.wsp;D173_PRINTER-928-Techs-west-L-E352dn
PrimWSP is : >;%;\\s173m928site.cambc.corpintra.net\928-Techs-west-L-E352dn
PrimWSP is : >;%;\\s173m928site.cambc.corpintra.net\928-Techs-west-L-E352dn
SecWSP is : ;>;%;\\s173mho1site.cambc.corpintra.net\928-Techs-west-L-E352dn
Exception while reading/writing csv file: java.lang.ArrayIndexOutOfBoundsException: 7

NOTE: I TRUNCATED THE OUTPUT. THERES ALOT MORE OF THESE ‘Null blocks’

  • 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-09T19:02:22+00:00Added an answer on June 9, 2026 at 7:02 pm

    It looks like your over complicating this. A CSV file has comma separated values. So your file data should look something like:

    Line 1: Cell 1,Cell 2, Cell 3, Cell 4, etc…

    Line 2: Cell 1 of row2, Cell 2 of row2, etc…

    Your using a tab delimited file so you need to split on the tabs

    //Read first line 
    String dataRow;
    int lineNumber = 0;
    while((dataRow = CSVFile.readline()) != null)
    {
        String [] dataArray;
        lineNumber++;
        String delimiter = "\t";
        dataArray = dataRow.split(delimiter); //Now dataArray contains all the tab delimited cells that were on line one of the .txt file
        //Start assigning the information to your variables since it is stored in dataArray
        String PrinterName = dataArray[0];//This would assign the first cell (row 1, column 1 in excel) that was read from the text file. From looking at your input this should be "Printer name"
        String Model = dataArray[1];
        String IP = dataArray[2];
        //etc...Assign the rest
        //Print your output
        //Do anything else you need to do
     }//end the while loop
    

    Here are some sources:

    http://www.java-examples.com/java-string-split-example

    Note: This example is closer to what you are doing just use “\t” instead of “,”:
    http://www.daniweb.com/software-development/java/threads/17262/reading-in-a-.csv-file-and-loading-the-data-into-an-array

    hope this helps

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

Sidebar

Related Questions

I'm trying to read data from an Excel document in C# using Microsofts COM
I am trying to Read HBase table TableMapReduceUtil and dump data into HDFS (Don't
I am trying to read data (which is actually an array) in Lisp from
I've been trying to read data (x/y axis, pressed buttons, etc) from a usb
I'm trying to read data from a.csv file to ouput it on a webpage
I'm trying to read a text file and store each line in a node
Trying to achieve any moving effect while appending an element from one to another
im trying to achieve something but i dont really know how I have set
What I'm trying to achieve is show count of lines starting with/ending with needle
What i'm trying to achieve is playing a guitar chord from my python application.

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.