Problem with RandomAccessFile

With the following code in the readfile() function, I can't read the RandomAccessFile it keeps going to the IOException. I'm just writing 20 names to a sequential file and putting four scores with each name. Then on the left side regular list order and on the right reverse list.  I was wondering if someone sees something I don't. Thanks.

import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.util.*;

public class file_test
{
String names[] ={"Matt", "Mike", "Sam", "John", "Mark", "Jane", "Josh", "Hank", "Doug", "Nick", "Brad", "Eric", "Kenn", "Phil", "Adam", "Jack", "Nate", "Gary", "Bill", "Bob"};
FileOutputStream fileout;
DataOutputStream data;
String out;
public file_test()
{
DataOutputStream data=null;
for (int a=0;a<20;a++){
names[a]+="                    ";
String gg=names[a];
names[a]=gg.substring(0,19);
}
try
{
data = new DataOutputStream(new FileOutputStream("F://out.dat"));
for(int a=0;a<20;a++)
    {
            data.writeUTF(names[a]);
                               
                for(int z=0;z<4;z++)
               {
                   int test=(int)(Math.random()*101);
                   data.writeInt(test);
                   }
       }//data.close();
  }
catch (IOException E)
{
    JOptionPane.showMessageDialog (null,"File Not Found");
}
}
public void readfile()
{
try
{
RandomAccessFile raf= new RandomAccessFile("F://out.dat", "rw");
for(int a=1;a<=20;a++)
{
int p1=(a-1)*38;
raf.seek(p1);
String s1=raf.readUTF();
int s2=raf.readInt();
int s3=raf.readInt();
int s4=raf.readInt();
int s5=raf.readInt();
out=s1+s2+"  "+s3+"  "+s4+"  "+s5+"   ";
int p2=(20-a)*38;
raf.seek(p2);
String t1=raf.readUTF();
int t2=raf.readInt();
int t3=raf.readInt();
int t4=raf.readInt();
int t5=raf.readInt();
//out+=t1+t2+"  "+t3+"  "+t4+"  "+t5+"\n";
System.out.printf(out);
}
}
catch(IOException e)
{
System.out.println("You got a mistake");
}
}
public static void main (String[]args)
{
    file_test app = new file_test();
    app.readfile();
}
}
bigmdawgAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Manikandan ThiagarajanSenior consultantCommented:
>>System.out.printf(out);

should be

System.out.print(out);

check your file is available or not
amol_chaudhariCommented:
hi bigmdawg,
                         first of all when u finish file_test function check whether the corrosponding file is created or not (check for file name F:\\out.dat). when u finish writing in the file close the handles (i.e. dataoutputstream) related to file.
                          in read file function u perform seeking by 38 bytes .. i think seek(19*(a-1)) is appropriate.......
hope this will help ................
bigmdawgAuthor Commented:
When i run the program the file is created. I made the adjustments and I'm still getting the IOException.
mrigankCommented:
Can you post the stack trace of the Exception that you are getting.
amol_chaudhariCommented:
hi
get the following code it is working

import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.util.*;

public class file_test
{
String names[] ={"Matt", "Mike", "Sam", "John", "Mark", "Jane", "Josh", "Hank", "Doug", "Nick", "Brad", "Eric", "Kenn", "Phil", "Adam", "Jack", "Nate", "Gary", "Bill", "Bob"};
FileOutputStream fileout;
DataOutputStream data;
String out;
public file_test()
{
DataOutputStream data=null;
for (int a=0;a<20;a++){
names[a]+="                    ";
String gg=names[a];
names[a]=gg.substring(0,19);
}
try
{
data = new DataOutputStream(new FileOutputStream("d:\\out.dat"));
for(int a=0;a<20;a++)
    {
            data.writeUTF(names[a]);
                               
                for(int z=0;z<4;z++)
               {
                   int test=(int)(Math.random()*101);
                   data.writeInt(test);
                   }
       }//data.close();
  }
catch (IOException E)
{
    JOptionPane.showMessageDialog (null,"File Not Found");
}
}
public void readfile()
{
try
{
RandomAccessFile raf= new RandomAccessFile("d:\\out.dat", "rw");
for(int a=1;a<=20;a++)
{
long p1=(a-1)*37;
raf.seek(p1);
String s1=raf.readUTF();
int s2=raf.readInt();
int s3=raf.readInt();
int s4=raf.readInt();
int s5=raf.readInt();
out=s1+s2+"  "+s3+"  "+s4+"  "+s5+"   ";
int p2=(20-a)*37;
raf.seek(p2);
String t1=raf.readUTF();
int t2=raf.readInt();
int t3=raf.readInt();
int t4=raf.readInt();
int t5=raf.readInt();
//out+=t1+t2+"  "+t3+"  "+t4+"  "+t5+"\n";
System.out.printf(out);
}
}
catch(IOException e)
{
System.out.println("You got a mistake");
e.printStackTrace(System.out);
}
}
public static void main (String[]args)
{
    file_test app = new file_test();
    app.readfile();
}
}
bye

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.