Solved

I/O codes

Posted on 1998-08-31
23
195 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java DateChooser? 3 36
object oriented programming comparison 5 72
servlet example 11 40
servlet filter example 37 63
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

803 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