Solved

I/O codes

Posted on 1998-08-31
23
200 Views
Last Modified: 2010-03-30
i want t o have some examples about reading values of bytes ,which are situated like datas in a memory in the file ,from file .and writing them to a text field .I would wellcome other examples about these subject.
0
Comment
Question by:murat080598
  • 15
  • 8
23 Comments
 
LVL 6

Expert Comment

by:gadio
ID: 1223017
murat, if you can be a bit more specific about what are the exact operations that you want to do, it will help giving you the answer.
0
 

Author Comment

by:murat080598
ID: 1223018
Hello gadio ,
i would like to send you exact information about this subject as an attachment to my email ,if you give me your email address . So, i m lookin for to hearing from you soon .
0
 
LVL 6

Expert Comment

by:gadio
ID: 1223019
murat, you can put this info here so that other people may come with answers as well. If you prefer doing it through email, past your email and I'll send you mine.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:murat080598
ID: 1223020
my email is implement@hotmail.com .i m waiting for your reply :)
0
 

Author Comment

by:murat080598
ID: 1223021
gadio , if you interested ,please reply soon or give an answer.
0
 
LVL 6

Expert Comment

by:gadio
ID: 1223022
sent.
0
 

Author Comment

by:murat080598
ID: 1223023
Did you get mine , is everything ok?
0
 
LVL 6

Accepted Solution

by:
gadio earned 50 total points
ID: 1223024
Yes I did. All is cool.
So, what you need is io code samples. Here is a sample that can read the file format that you have. Hope that helps.

------------------- file ----------------


public class readSpecialHexFile {

    /**
     * Constructor.
     */
    public readSpecialHexFile () {
    }

    public static void main(String args[]) {
        HexArray ha = new HexArray();
        try {
            ha.read("/home/gadio/temp/inputexample.file");
            ha.showAll();
        } catch( Exception e ) {
            System.out.println(e);
        }
    }
}


------------------- file ----------------




import java.io.*;
import java.util.*;

public class HexArray {
    Vector data;
    int columns;

    public HexArray() {
        data = new Vector();
        columns = 0;
    }

    public void read( String filename ) throws FileNotFoundException {
        FileReader fr = new FileReader(filename);
        LineNumberReader lnr = new LineNumberReader(fr);
        Vector all_data = new Vector();
        Vector line_data = new Vector();
        String line;
        try {
            while( (line = lnr.readLine()) != null ) {
                StringTokenizer st = new StringTokenizer(line);
                String token;

                while( st.hasMoreTokens() ) {
                    token = st.nextToken();
                    line_data.addElement( new Long( Long.parseLong(token,16) ) );
                }
                all_data.addElement(line_data);
                if( line_data.size() > columns ) columns = line_data.size();
                line_data = new Vector();
            }
            fr.close();
            data = all_data;
        } catch( IOException e ) {}
    }

    public int getRowsNumber() {
        return data.size();
    }

    public int getColumnsNumber() {
        return columns;
    }

    public long getItemAt( int row, int column ) {
        try{
            Vector line = (Vector)data.elementAt(row);
            Long item = (Long)line.elementAt(column);
            return item.longValue();
        } catch( Exception e ) {}
        return -1;
    }

    public void showAll() {
        System.out.println("rows: "+getRowsNumber()+"   cols: "+getColumnsNumber())
;
        for( int r = 0; r < getRowsNumber(); r++ ) {
            for( int c = 0; c < getColumnsNumber(); c++ ) {
                System.out.print( getItemAt(r,c) + "\t");
            }
            System.out.println("");
        }
    }
}





0
 
LVL 6

Expert Comment

by:gadio
ID: 1223025
Note that I have converted the hex numbers to long, but they could have been placed in shorts.
0
 

Author Comment

by:murat080598
ID: 1223026
Gadio thanks for your codes , i think they are excellent .Keep in touch!
With my regards.
0
 

Author Comment

by:murat080598
ID: 1223027
Gadio the codes gives these errors , do you have any idea of getting rid of these problems?
murat

ERRORS ARE:
file.java:18: Class or interface declaration expected.
import java.io.*;
^
file.java:1: Public class readSpecialHexFile must be defined in a file called "readSpecialHexFile.java".
public class readSpecialHexFile{
             ^
file.java:22: Class Vector not found in type declaration.
        Vector data;
                   ^
file.java:26: Class Vector not found in type declaration.
        data = new Vector();
                   ^
4 errors
0
 
LVL 6

Expert Comment

by:gadio
ID: 1223028
Yes. You have name the java file as file.java while each one of the files should have been called the same as the class in it, that is the names are:
readSpecialHexFile.java
and
HexArray.java
I took it for granted and didn't mentioned the file names, :-]
Sorry. Tell me if there are other problems.
0
 

Author Comment

by:murat080598
ID: 1223029
did youmget my last mail , do you think it is  possible to be done?
0
 

Author Comment

by:murat080598
ID: 1223030
th others
HexArray.java:5: Class or interface declaration expected.
*
^
HexArray.java:24: Class Vector not found in type declaration.
 private Vector data;
                    ^
HexArray.java:28: Class Vector not found in type declaration.
    data = new Vector();
               ^
3 errors
0
 
LVL 6

Expert Comment

by:gadio
ID: 1223031
I think that you should check your classpath. Is it pointing to the classes.jar (or zip)? What verion of jdk are you using?

0
 

Author Comment

by:murat080598
ID: 1223032
jdk 1.4 ,please check your email , and i m looking for your email ,ok?
0
 

Author Comment

by:murat080598
ID: 1223033
i m looking forward to get your reply for my last mail which i sent to the new address
0
 
LVL 6

Expert Comment

by:gadio
ID: 1223034
Yes - got it.
0
 

Author Comment

by:murat080598
ID: 1223035
hi gadio  check your mail!
0
 

Author Comment

by:murat080598
ID: 1223036
gadio did you receive my last mails?
0
 

Author Comment

by:murat080598
ID: 1223037
gadio give me a reply
0
 

Author Comment

by:murat080598
ID: 1223038
Hi Gadio , i m waiting for your reply
0
 

Author Comment

by:murat080598
ID: 1223039
Hi gadio,
if you received my letters plase give me an answer expreessing your taughts about them.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
factorial example 4 50
Running JavaFX on JDeveloper 12C 1 55
Glassfish admin console not working 1 35
Java Eclipse Loop 3 21
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question