Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

I/O codes

Posted on 1998-08-31
23
Medium Priority
?
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 200 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

609 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