dcsimg
Question: Serializing a File Descriptor
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Mohana_G
Posted On:   Friday, June 14, 2002 11:25 AM

After reading a text file, I would like store the File Descriptor in an other text file, so that later I could start reading from the point where I stopped. is it possible through the concept of Serialization. Please let me know I tried doing it but I get an error: java.io.NotSerializableException: java.io.FileDescriptor Here is the source code of what I have tried import java.io.*; class test implements Serializable { FileDescriptor fd; public void trace() { FileInputStream f; try { int lines=0; File file = new File("tmp"); if(file.exists()) { FileInputStream descript   More>>


After reading a text file, I would like store the File Descriptor in an other text file, so that later I could start reading from the point where I stopped. is it possible through the concept of Serialization.

Please let me know I tried doing it but I get an error:

java.io.NotSerializableException: java.io.FileDescriptor





Here is the source code of what I have tried



import java.io.*;

class test implements Serializable
{
FileDescriptor fd;
public void trace()
{
FileInputStream f;

try
{

int lines=0;
File file = new File("tmp");
if(file.exists())
{
FileInputStream descriptor = new FileInputStream("tmp");
ObjectInputStream o = new ObjectInputStream(descriptor);

fd = (FileDescriptor) o.readObject();
o.close();
f = new FileInputStream(fd);
}
else
{
f = new FileInputStream("convert.txt");
}
for(int i=0;i <80;i++)
{
lines = f.read();
}
fd = f.getFD();
System.out.println(lines +"rrrr");
FileOutputStream fis = new FileOutputStream("tmp");
ObjectOutputStream s = new ObjectOutputStream(fis);

s.writeObject(fd);
s.flush();
fis.close();
}
catch(Exception e)
{
System.out.println(e);
}
}

}

class FDtest
{
public static void main(String[] arg)
{
test s = new test();
s.trace();
}
}

   <<Less
About | Sitemap | Contact