Problem of reading the content of this .txt files

currently i have a problem of reading the content of this file castle.txt
#Server Ready.
Lee Siaw Kang 50256808:08:382004/03/15Abdul Rahman 60296008:13:242004/03/15Kenneth Lee 60299308:13:532004/03/15Ho Kid Peng 31337508:17:442004/03/15Tonny Sherbern 50271108:19:132004/03/15Frederick Foh 50257908:20:212004/03/15Jason Kho 61702908:21:312004/03/15Lois Lee Liarn Huee 61897408:22:522004/03/15Victor Palau Udih 31337308:23:202004/03/15Michelle Sim 61899008:27:412004/03/15Alan Hong 50262708:30:312004/03/15Frederick Foh 50257908:33:412004/03/15Douglas Aseng 50255808:36:442004/03/15Atika Abang 31347508:36:592004/03/15David Dzrandinuraidi 61239608:38:012004/03/15Sentia Brangking 61896808:39:502004/03/15Dinah Samuel 61704608:40:582004/03/15Dr. Anderson Tiong 61702508:42:102004/03
it is something like this ...i want to break it into readable format ...i have tried vector with is the following code.
import java.util.*;
import java.io.*;
public class parseCastle {
public static Vector parseInfo(String str) {
int recordSize = 59;
Vector v = new Vector();
for (int i=0; i<str.length(); i+=recordSize) {
String str1 = str.substring(i, i+recordSize);
Vector vi = new Vector();
vi.addElement(str1.substring(0, 35));
vi.addElement(str1.substring(35, 41));
vi.addElement(str1.substring(41, 49));
vi.addElement(str1.substring(49, 59));
v.addElement(vi);
return v;
//constructor
parseCastle(){
try
FileInputStream fin = new FileInputStream("castle.txt");
File fprop = new File("castle.txt");
byte[] data = new byte[(int)fprop.length()];
int total = fin.read(data);
if (total != data.length) {
System.err.println("Error loading file");
return;
//System.out.println(data.length);
Vector v = parseInfo(new String(data));
for (int i=0; i<v.size(); i++) {
Vector vi = (Vector)v.elementAt(i);
for (Enumeration e = vi.elements(); e.hasMoreElements();)
System.out.println(e.nextElement());
System.out.println();
//*** Alternative ***
//for (int k=0; k<vi.size(); k++)
// System.out.println(vi.elementAt(k));
catch (IOException e)
     System.out.println("Error: "+e);
     e.printStackTrace();
But it gave me error. like it exceeds array boundary...can someone expert help me out

You should be aware that these kind of effort always involves certain amount of risk because the proper record format is not hundred percent guaranteed. So, make sure to use properly formatted file, or genuine database instead.
import java.io.*;
import java.util.regex.*;
public class ParseCastle2{
  public static void main(String[] args) throws Exception{
    String line, data;
    BufferedReader br = new BufferedReader(new FileReader("castle.txt"));
    br.readLine(); //discard #Server Ready line
    line = br.readLine();
    Pattern pat = Pattern.compile("([ .A-Za-z]+)([/0-9:]+)");
    Matcher mat = pat.matcher(line);
    Pattern subPat = Pattern.compile("(\\d+):(\\d\\d:\\d\\d)(.+)");
    while (mat.find()){
      System.out.println(mat.group()); // if name only, use group(1) ... beware trailing space
      data = mat.group(2);
      Matcher subMat = subPat.matcher(data);
      while (subMat.find()){
        System.out.println(" cdID = " + subMat.group(1));
        System.out.println(" Time = " + subMat.group(2));
        System.out.println(" Date = " + subMat.group(3));

Similar Messages

  • How to read the content of this excel file in LV

    Hi could you please let me know how can I read the content of this excel file using the Read From Speardsheet function. It contains text and numbers
    Thanks
    The excel file is attached
    Attachments:
    Datalogging.zip ‏307 KB

    Check attached VI.
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.
    Attachments:
    ReadFromExcel.vi ‏27 KB

  • Error in reading the contents of a zip file

    EHello Experts,
    I want to read the contents of a zip file.I have written the following program which reads the contents of a file named "index.xml" which resides in ReadZip.zip.My problem is , it is reading only the first line of that file & after that it is giving this error.
    java.io.IOException: Stream closed
    at java.util.zip.ZipInputStream.ensureOpen(ZipInputStream.java:43)
    at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:67)
    at components.ReadZipFile2.main(ReadZipFile2.java:26)
    public class ReadZipFile2 {
        public static void main(String args[]) {
            try {
                FileInputStream fis = new FileInputStream("C:\\ReadZip.zip");
                ZipInputStream zis = new ZipInputStream(fis);
                ZipEntry ze;
                while ((ze = zis.getNextEntry()) != null) {
                    System.out.println(ze.getName());
                    if (ze.getName().equals("ReadZip/index.xml")) {
                        long size = ze.getSize();
                        if (size > 0) {
                            System.out.println("Length is " + size);
                            BufferedReader br = new BufferedReader(
                                    new InputStreamReader(zis));
                            String line;
                            while ((line = br.readLine()) != null) {
                                System.out.println(line);
                            br.close();
            } catch (IOException e) {
                e.printStackTrace();
    }It seems that zis is getting close after reading the first entry of file.I am unable to guess the reason for this.Please help.Thanx in advance.

    [redacted confused advice]
    [_Compressing and Decompressing Data using Java - with many code samples_|http://java.sun.com/developer/technicalArticles/Programming/compression/|Yes Virginia, there really are code samples]

  • Populate a table reading the data from a TXT file

    how can I populate a table reading the data from a TXT file?
    thanks

    Hey Kevin!
    Using FORMS.TEXT_IO to bulk load data from a file strikes me as re-inventing the wheel. It is just about justifiable in a self-service environment, but I regard the EXTERNAL TABLE is a better solution for that situation as well.
    The same applies to UTL_FILE. I think the ability to read text with UTL_FILE is primarily intended for read file-based configuration or file manipulation/processing rather than data loading.
    Re-writing a text file into SQL statements is too much like hard work (even with an editor that supports macro definition and regular expressions) for no real benefit. You lose all the bulk load peformance you would get from SQL*Loader. But for QAD I'd probably let you off with it.
    You missed out one obvious alternative: using Java to turn the contents of an XML file into a CLOB and inserting it into a table which is read by a PL/SQL procedure that parses the XML records and insert the retrieved data into a table.
    Stay lucky, APC

  • How to read the content of ms-word file use pure java???

    how to read the content of ms-word file use pure java???

    hi,
    check this: http://jakarta.apache.org/poi/

  • How to read the content of a text file (by character)?

    Guys,
    Good day!
    I'm back just need again your help. Is there anyone knows how to read the content of a text file not by line but by character.
    Please help me. Thank you so much in advance.
    Jojo

    http://java.sun.com/javase/6/docs/api/index.html
    package java.io
    InputStream.read(): int
    Reads the next byte of data from the input stream.
    Implementation:
    InputStreamReader
    An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted.

  • Can a search engine read the contents of a Library file embedded in a page?

    Can a search engine read the contents of a Library file
    embedded in a page? Or would SSI be the way to go. I'm creating a
    large library of text-based information and links, and I want to
    have much of it modular so I can add a link and all the many pages
    on my site updates to reflect the change. A big concern is that
    when a search engine visits my site, can it read the content
    embedded in the library item, or is SSI a better method to help the
    search engine read my content?
    Thanks

    Yes, search engines can read Dreamweaver library items. The
    library only exists on your own hard drive. Once you add the
    library item to your pages it's in there as regular HTML.
    If you have more than 20 pages on your site, they say SSI is
    better, because when you update you only update the SSI. If you
    stick with library items each page has to be uploaded every time
    the library is updated.

  • Help on how to read the content of an XML file from the payload

    I have a receiver channel / mail adapter, that sends e-mails with a XML attachment.
    I’m trying to write a Bean, that should make it possible to rename the attached XML file dynamically.
    In the Bean I want to read the content of the attached XML file, it could be the “order number”.
    The filename should then be “Order number”.XML.
    <u><i>Can anyone help me with how to read the content of the XML file from the payload.</i></u>
    <i><b>Frank</b></i>

    hi,
    check this: http://jakarta.apache.org/poi/

  • How to read the data in a txt file on a web site?

    I want to extract the numbers located in txt files on a web site. It's a normal url. Not a ftp.
    Does anyone know how to do it?

    Hi Tom,
    What do you want to extract from the text file??
    I wanted to extract an IP address from a pearl script from my FTP server and this was the vi that I used .I dont know if you are trying to do the same?
    Here is the vi.It is in LV 7.1
    Hope its helps .
    Good luck.
    ohiofudu.
    Certified LabVIEW Architect
    Certified TestStand Developer
    Attachments:
    PublicIP-Adresse.vi ‏31 KB

  • ITunes just told me that it "can't read the contents of this iPhone, click

    the restore tab to restore this phone to factory settings".
    What caused this? I just bought the phone yesterday and it seemed to synch with only one problem.
    That problem was that the music on my old 3G phone didn't get copied over as it wasn't in my iTunes library anymore. Somewhere along the line, my pc hard drive filled up and I had to move all of my music to an external hard drive. I never bothered resynching it with iTunes, I just manually added albums to itunes periodically as I wanted to listen to them.
    So today I went ahead and added the Music folder on my external drive to my iTunes library so that I could readd my lost music to my phone.
    Now, after that operation completed, I get this error message. What gives? I think it's possible that the two aren't related. I'm really worried that I'm going to lose all of my data! Please help.

    I've seen it. Typically when I update my or my wife's iThings, there's some kind of issue, probably because we sync the devices so rarely. Usually a cold reboot of both the iThing and iTunes fixes this.
    To sync my iPad for the first time I had to reboot the computer itself (Mac Mini).
    You are not alone I just feel sorry for the folks who restore their phone without first toggling the unit state of the on-off attenuator.
    Message was edited by: Kurt Kober

  • I want to read the content of a text file dropped in a watched folder into a string variable

    I have a workbench process with 2 variable.
    inDoc (DataType=Document/input/required)
    outStr (DataType = String/output)
    The document being passed to the workflow is a text file with 4 lines of text in it.  when the text file is dropped into the watched folder, it will be assigned to the inDoc parameter in the workflow.
    My workflow needs to extract the 4 lines of text and write it into a string (outStr).
    Id like to use the FileUtilsService.ReadString service but i can't since its input parameter is the file path.  When i do, i get the following error...
    Caused by: ALC-FUT-001-011: File rO0ABXNyABZjb20uYWRvYmUuaWRwLkRvY3VtZW50yAEFUxsO+CEDACNJAAtfY2FsbGJhY2tJZFoADV9kZXNlcmlhb Gl6ZWRJABBfZGlzcG9zYWxUaW1lb3V0WgAJX2Rpc3Bvc2VkWgAZX2lzRGlzcG9zYWxUaW1lb3V0RGVmYXVsdFoAE19 pc1RyYW5zYWN0aW9uQm91bmRKAAdfbGVuZ3RoSQAOX21heElubGluZVNpemVaAAhfb3duRmlsZVoAC19wYXNzaXZhd GVkWgALX3BlcnNpc3RlbnRJABFfc2VuZGVyQ2FsbGJhY2tJZFoAEV9zZW5kZXJQYXNzaXZhdGVkWgARX3NlbmRlclB lcnNpc3RlbnRJAA5fc2VuZGVyVmVyc2lvbkkABl9zdGF0ZUwAC19hdHRyaWJ1dGVzdAATTGphdmEvdXRpbC9IYXNoT WFwO0wACF9jYWNoZUlkdAAfTGNvbS9hZG9iZS9pZHAvRG9jdW1lbnRDYWNoZUlEO0wADF9jYWxsYmFja1JlZnQAIUx jb20vYWRvYmUvaWRwL0lEb2N1bWVudENhbGxiYWNrO0wADF9jb250ZW50VHlwZXQAEkxqYXZhL2xhbmcvU3RyaW5nO 0wAC19kYXRhQnVmZmVydAAeTGNvbS9hZG9iZS9zZXJ2aWNlL0RhdGFCdWZmZXI7TAAPX2V4cGlyYXRpb25UaW1ldAA QTGphdmEvbGFuZy9Mb25nO0wABV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U0 1MjU3XzAxLTIwMTFfM3xOfHx8fHx8fHx8fDIwMDB8Nnx8fGFzZGZ8YXNkZnxhc2RmfDI1Nnx8fHx8fHx8fHx8fHx8f Hx8fHx8DQpJTU01MjU3XzAxLTIwMTFfNHxOfE58fE58TnxOfHxOfE58fE58TnxOfA0KSU1NNTI1N18wMS0yMDExXzV 8U2luZ2xlfDAxfHwyMDEyfDAyfDE4fDIwMTJ8MDN8MDN8MjM0fGFzZGZ8fGFzZGZhc3x8fHxFeGNoYW5nZS1Qcm8uO S40MDEuRnVsbC5XSU4uZW5fQ0EuRU5VLTEwLTIwMTF8DQoNCnBwdwYAAAAAAAB0AAp0ZXh0L3BsYWlucHNyABFqYXZ hLnV0aWwuSGFzaE1hcAUH2sHDFmDRAwACRgAKbG9hZEZhY3RvckkACXRocmVzaG9sZHhwP0AAAAAAAAx3CAAAABAAA AADdAAKd3NmaWxlbmFtZXQAJ0M6XFVzZXJzXENodWxseS5QYXJrXERlc2t0b3BcaGRzY2FuLnR4dHQACGJhc2VuYW1 ldAAKaGRzY2FuLnR4dHQABGZpbGVxAH4AFXh3NwAtYWRvYmUvaWRwL0RvY3VtZW50UHVsbFNlcnZhbnQvYWRvYmVqY l9MQ19ERVYx//////////94 does not exist.
    at com.adobe.livecycle.fileutils.FileUtilsService.readDocument(FileUtilsService.java:363)
    which is what i expected...
    I've also tried with the Script.executeScript to call some java code but im not too strong in java and in all the examples i find, the file pointer requires a file path.
    import java.io.*;
    FileInputStream f = new FileInputStream(patExecContext.getProcessDataValue("/process_data/inDoc"));
    OR
    File f = new File(patExecContext.getProcessDataValue("/process_data/inDoc"));
    OR
    File f = patExecContext.getProcessDataValue("/process_data/inDoc");
    Any clue how to resolve my problem?

    Try the following code snippet to read the String content from the file recieved through watched folder endpoint.
    com.adobe.idp.Document inputDoc = patExecContext.getProcessDataDocumentValue("/process_data/inDoc");
    java.io.InputStream inStream = inputDoc.getInputStream();
    byte[] dataBuffer = new byte[inStream.available()];
    inStream.read(dataBuffer);
    String strData = new String(dataBuffer);
    patExecContext.setProcessDataStringValue("/process_data/outStr",strData);
    The code is not tested, hence if you find any mistakes, correct and test the functionality.
    Nith

  • Read the content of a properties file

    I have a properties file(.properties), which has contents in this format:-
    [1]TYPE=4
    [1]ENABLED=TRUE
    [1]Caption = "Kozos"
    [1]URL=https://kozos.com/access
    I want to display the value of url for kozos and when i try below code, i get an error :- 
    ConvertFrom-StringData : Data line 'D:\kozos.properties' is not in 'name=value' format. 
    Clear-host
    $FileName = "D:\kozos.properties"
    $file_content = $FileName -join [Environment]::NewLine
    $configuration = ConvertFrom-StringData($file_content)
    $environment = $configuration.'kozos'
    Write-host "Environment is $environment"

    The data you initially gave had more than that (Type and Enabled) which is what I was going on. From what I understand, you only want the Caption and associated URL available? Do you actually need the numbers from the file ([1],[2], etc...)? Here are a couple
    of alternative approaches (which may be changed depending on your feedback regarding my questions).
    $Configuration = [pscustomobject][hashtable](ConvertFrom-StringData (((Get-Content .\kozos.properties) -replace '\[.*\]') | Out-String))
    ($Configuration | Where {$_.Caption -match '"kozos"'}).url
    $Configuration = (ConvertFrom-StringData (((Get-Content .\kozos.properties) -replace '\[.*\]') | Out-String))
    $hash = @{}
    $Configuration | ForEach {
    $hash[($_.caption -replace '"')] = $_.url
    $hash.Kozos
    Others may have alternative approaches to this as well.
    Boe Prox
    Blog |
    Twitter
    PoshWSUS |
    PoshPAIG | PoshChat |
    PoshEventUI
    PowerShell Deep Dives Book
    Boe,
    I want only the Caption and the url associated with it. I ran your code, this is the error i got :-
    ConvertFrom-StringData : Data item 'TYPE' in line 'TYPE=14' is already defined.  
    THis is what the properties contains :-
    [1]TYPE=4
    [1]ENABLED=TRUE
    [1]Caption = "Kozos"
    [1]URL=https://kozos.com/access
    [2]TYPE=4
    [2]ENABLED=TRUE
    [2]Caption = "Kozos1"
    [2]URL=https://kozos1.com/access
    [3]TYPE=4
    [3]ENABLED=TRUE
    [3]Caption = "Kozos"
    [3]URL=https://kozos.com/access and
    goes till 100.
    I apologise for not mentioning this on top.

  • URGENT: How to read the content of a PDF-file in Java?

    Hello
    What I need are some classes which can read a pdf and translate it in normal Text, so that I can write the content of the pdf in my database.
    Where can I find those classes? Or how else could I get there?

    www.lowagie.com/itext
    www.etymon.com/pj
    www.retep.org.uk/pdf
    www.pdflib.comwww.pdfzone.com
    www.planetpdf.com
    www.purepdf.com
    www.adobe.com
    www.pdfstore.com
    www.adobe.com/proindex/acrobat/formsresources.html
    www.partners.adobe.com/asn/developer/acrosdk/forms.html
    www.rrsys.com
    www.javafoundry.com/javapdf
    www.novagraphix.com/internet_publishing_with_acrobat/forms/forms_tutorial.html
    www.binarything.com

  • How to read the contents of a text file and populate the data in a table ?

    Hello All,
      Can anyone advise on how to acheieve the above ? I am trying to read in a text file (CSV) and have the contents populated to the respective UI elements in a table. Any help is greatly appreciated.
    from
    Kwok Wei

    Hi,
    Let us consider you have list of names(Seperated by delimeter) in a text file and you want to display in  a table.
    1. Create Context Node "Names" and context attribute "Name"
    2. Create Table and bind to the above context.
    3.Write the following code in the "Init method.
    try{
    FileReader f =new FileReader("");
    BufferedReader r=new BufferedReader(f);
    String names=r.readLine();
    Vector Names=new Vector();
    // Use Tokenizer and store all the names i a vector//
    for(int i=0;i<Names.size();i++){
    IPrivate<<VieName>>.INameElement ele=wdContext.createNameElement();
    ele.set<<Name>>( Names.get(i).toString());
    wdContext.NodeName().addElement(ele);
    Regards, Anilkumar
    Message was edited by: Anilkumar Vippagunta

  • VBScript to read the content of a .csv file and delete old files mentioned in the .csv

    I have a Windows 2003 file server.
    I have generated a report in .csv format, about the files which are older than 1 year.
    I need a VBScript to read the .csv file and delete the files which are enlisted there.
    Can someone please help me with this?

    Look into the "Learn" link above.  There are resources and instructions on how to write VBScript code.  Look into how to use the FileSystemObject.
    ¯\_(ツ)_/¯

Maybe you are looking for