Solved

I/O codes

Posted on 1998-08-31
23
183 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

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

Author Comment

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

Expert Comment

by:gadio
Comment Utility
sent.
0
 

Author Comment

by:murat080598
Comment Utility
Did you get mine , is everything ok?
0
 
LVL 6

Accepted Solution

by:
gadio earned 50 total points
Comment Utility
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
Comment Utility
Note that I have converted the hex numbers to long, but they could have been placed in shorts.
0
 

Author Comment

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

Author Comment

by:murat080598
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 6

Expert Comment

by:gadio
Comment Utility
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
Comment Utility
did youmget my last mail , do you think it is  possible to be done?
0
 

Author Comment

by:murat080598
Comment Utility
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
Comment Utility
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
Comment Utility
jdk 1.4 ,please check your email , and i m looking for your email ,ok?
0
 

Author Comment

by:murat080598
Comment Utility
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
Comment Utility
Yes - got it.
0
 

Author Comment

by:murat080598
Comment Utility
hi gadio  check your mail!
0
 

Author Comment

by:murat080598
Comment Utility
gadio did you receive my last mails?
0
 

Author Comment

by:murat080598
Comment Utility
gadio give me a reply
0
 

Author Comment

by:murat080598
Comment Utility
Hi Gadio , i m waiting for your reply
0
 

Author Comment

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
for i loop in grovy 1 32
Unable to start eclipse ? 17 82
micro services spring boot application error 3 23
maven project error 5 19
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now