aspose file tools*
The moose likes I/O and Streams and the fly likes How do I find a text file is Unix or Dos format via Java API? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How do I find a text file is Unix or Dos format via Java API?" Watch "How do I find a text file is Unix or Dos format via Java API?" New topic
Author

How do I find a text file is Unix or Dos format via Java API?

walter wang
Ranch Hand

Joined: Jun 02, 2001
Posts: 154
Hello All,

How could I find out a text file is unix or dos format? is there anyway to do it via java api or methods?


thanks in advance


public class Walter { public boolean is_Working_Now (boolean is_boss_Coming) { return is_boss_Coming; }
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41859
    
  63
You could count how many newline characters it contains, and how many carriage return characters, and code up a rule of thumb based on their ratio.


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

In DOS format they should be equal, in Unix format the number of carriage return should be 0. You'll need to find out what to do if:
  • the number of carriage returns is between 0 and the number of line breaks
  • the number of carriage returns is larger than the number of line breaks, with special subcase if the number of carriage returns is larger than 0 and the number of line breaks is 0 (basically an old Mac OS file)


  • SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
    How To Ask Questions How To Answer Questions
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: How do I find a text file is Unix or Dos format via Java API?