Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
walter wang
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic