473,379 Members | 1,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Convert simply text file into array

1
Hello.. i would like to ask you. Its long time i did something in java.. and now I am lost. :)
I have text file with constant elements in line but variable number of lines... text file looks like
asdf 12 54 12
brjk 45 2 14
etc..
I want to make array from this file. Can you help me with my code? This not working..

Expand|Select|Wrap|Line Numbers
  1. String[] part = new String[5];
  2.         BufferedReader f = null;
  3.         try{
  4.             f = new BufferedReader(new FileReader(filename));
  5.             String something=null;
  6.             while((something=f.readLine())!=null){
  7.                 part = something.split(" ");
  8.             System.out.print(part[0]);
  9.             }
  10.  
  11.         } catch (IOException ex) {
  12.             Logger.getLogger(Hlavni.class.getName()).log(Level.SEVERE, null, ex);

all comments are appreciated..
May 30 '15 #1
1 1606
chaarmann
785 Expert 512MB
What error message do you get? Please show us the exact error message, so we can help.
Maybe you should test in your code if the splitted string array contains at least 1 element before accessing the first element.
Jun 1 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Dilantha Seneviratne | last post by:
Hi Could someone advice me on how I could convert an indented text file into a xml file. Any help is greatly appreciated. thanx example indented text file looks like the following ...
4
by: kalio80 | last post by:
Hi everyone I posted an enquiry earlier about using c++ code to convert text files between linux & widows. I ended up with this code: #include <iostream> #include <fstream> using namespace...
2
by: Gustaf Liljegren | last post by:
I'm writing a console program that is supposed to read a bunch of old text files written in CP437 encoding, extract parts of them and output well-formed XML in UTF-8. First problem I run into is to...
4
by: Carsten Kraft | last post by:
Hello Newsgroup, I think this is easy for you: I want to save the data line by line into an string array. eg. Text file: Array Line 1 Line1
11
by: JimN1 | last post by:
Hi, I am looking for an example to convert a flat text file with variable length records to a flat file with fixed length records. Does anyone have an example?
9
by: olivercfc | last post by:
Hello All, I have a text file in the following format < line 1 line 2 line 3 line < 4 line > 5
15
by: javadeveloper | last post by:
Can anybody help me with the code regarding how to convert a text file to JPG file... Its really urgent for me.. I was able to convert a text file to PDF.. But now I need to convert a text file to...
2
by: progvar | last post by:
Hi! can any one help me by providing the method when i open any text file and convert into pdf format. I searched on the net and i got some code but i am not understanding this code and it also...
7
by: chelle2100 | last post by:
hi... i need to write a converter to convert the text file to a binary file with the following file format... CharacterCount:Unsigned Char(This stores the number of characters that is in the file)...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.