This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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: 42972
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
Posts: 21047
85
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
    Boost this thread!