Files

what is the method to check if a file is stored in byte format or text format?
[85 byte] By [Arpanaa] at [2007-10-2 10:59:56]
# 1
There isn't one. A file is just a series of bytes in the end. There is really no such thing as a "text" file. It may be thought of as a "text" file if you read it and only find characters within a certain range in it.
warnerjaa at 2007-7-13 3:28:51 > top of Java-index,Java Essentials,New To Java...
# 2
Then why do we need different stream classes?for files? for displaying?and not for reading?
Arpanaa at 2007-7-13 3:28:51 > top of Java-index,Java Essentials,New To Java...
# 3

If the files are stored in byte format in the end then why do we have FileReader and FileWriter for text files and FileInputStream and FileOutputStream for byte files?

How can we know before handling a file that a file is a text document file(without checking the secondary name, ) or a byte format file

Arpanaa at 2007-7-13 3:28:51 > top of Java-index,Java Essentials,New To Java...
# 4
help please quickly.
Arpanaa at 2007-7-13 3:28:51 > top of Java-index,Java Essentials,New To Java...
# 5

The fact of the matter is that all files are in byte format. However in the case of text files, it is simply the case that those bytes represent characters.

In fact, one can view any file in text form. It's just that it might not make any sense

There is no easy way to check format because 'format' can mean many, many different things.

Now, as to why there are different types of stream classes.

Input can come from many different sources. Reading from a file is for instance quite different then reading from the network.

As for your example of FileReaders and FileInputStreams and all that:

You do not NEED to use different streams. It's just that readers/writers are more convient for text. You COULD use Input/Output streams.

Laughingmana at 2007-7-13 3:28:51 > top of Java-index,Java Essentials,New To Java...
# 6

I was expecting this code to display text file

It compiles well, and when executing displays some weird characters.

How do I make it display the content of the textfile shakun.doc ditto?

import java.io.*;

public class FileOper

{

public static void main(String args[])throws IOException{

FileReader fr=new FileReader("c:\\Bluej\\examples\\shakun.doc");

BufferedReader p=new BufferedReader(fr);

String s;

while((s=p.readLine())!=null){

System.out.println(s);

}

p.close();

}

}

Arpanaa at 2007-7-13 3:28:52 > top of Java-index,Java Essentials,New To Java...
# 7
Why isnt anyone responding? Is it such a big task to read a text file and display as it is on the screen using FileReader in Java.?
Arpanaa at 2007-7-13 3:28:52 > top of Java-index,Java Essentials,New To Java...
# 8
I would suspect that this shakun.doc file doesn't contain simple "text" (sequences of displayable characters delimited by newline sequences). What happens when you "type" it from the command line?
warnerjaa at 2007-7-13 3:28:52 > top of Java-index,Java Essentials,New To Java...
# 9
Seeing as you were being so patient, I thought I would respond.
phawdona at 2007-7-13 3:28:52 > top of Java-index,Java Essentials,New To Java...
# 10
Hai Ram!Why have you not read the tutorial on RandomAccessFiles, low-level streams, high-level filter streams, and readers & writers?Do you expect a MSWord document- a file whose extension is ".doc" to magically display (just a Krishna does)?
filestreama at 2007-7-13 3:28:52 > top of Java-index,Java Essentials,New To Java...
# 11
Google [ java poi ].
tschodta at 2007-7-13 3:28:52 > top of Java-index,Java Essentials,New To Java...
# 12
You are right warnerja, when I tried to type the contents thru type command at the command prompt, the doc file showed vague characters, but I created shakun.doc and typed in text into it. and Iam verry sure no complicated stuff is in it.Why is this happening.
Arpanaa at 2007-7-13 3:28:52 > top of Java-index,Java Essentials,New To Java...
# 13
Mahadeva on a bicycle!Didn't you read my post as well as that of others?! Why do you insist on posting baqwaaz?
filestreama at 2007-7-13 3:28:52 > top of Java-index,Java Essentials,New To Java...