1

When a I do ls for a file in linux and I see: crw-rw---- what does the c imply?
I mean I read that c is for character device but is there any consequence on which Java API I/O methods I will use (e.g. BufferedWriter etc) or must not use?

Jim
  • 18,826
  • 34
  • 135
  • 254

2 Answers2

1

I think this should give sufficient advice. FileInputStream and FileOutputStream are sufficient to access the device file which in turn talks to the character device.

demongolem
  • 9,474
  • 36
  • 90
  • 105
  • I read the attached link.Why does it use `0,1,4` as values for a character file?I am lost on this point – Jim Jan 08 '13 at 10:35
  • @Jim In this case, they are hardware specific values for SUZAKU-V. – demongolem Jan 08 '13 at 14:23
  • I mean in the post it uses `FileOutputStream`/`FileInputStream` is for 8-bit data right? Character devices is for ASCII? What about signed vs unigned 8-bit? – Jim Jan 09 '13 at 07:18
  • @Jim - Right, the read and write methods used work on the Java primitive type `byte`. From [Oracle's Java site](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html), The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation. – demongolem Jan 09 '13 at 14:56
  • So this approach will work as long as the the file contains signed 8-bit ints? Not for unsigned 8-bit ints? – Jim Jan 10 '13 at 08:13
  • @Jim Let me refer you to [this](http://stackoverflow.com/questions/9578639/best-way-to-convert-a-signed-integer-to-an-unsigned-long) and [this](http://stackoverflow.com/questions/11088/what-is-the-best-way-to-work-around-the-fact-that-all-java-bytes-are-signed?rq=1) regarding Java's proclivity for signed bytes and what to do about that. – demongolem Jan 10 '13 at 16:12
  • @demongolem Your link is now broken – Knossos Oct 28 '14 at 11:48
0

This wikipedia explains the usage of the c character.

crw-rw-r-- a character special file whose user and group classes have the read and write permissions and whose others class has only the read permission.

This c character will not affect your ability to read this file, however you may want to check the write permissions if you are not in correct group. There are much better ways to check read/write permissions on files rather than reading through ls.

Use File.canWrite() and File.canRead() for checking file permissions. More info on these methods here - File - JavaDoc.

Tom
  • 15,798
  • 4
  • 37
  • 48