Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Line terminator in file  RSS feed

 
Kudret Serin
Ranch Hand
Posts: 167
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How can I understand which line terminator (windows or linux) used in file without reading file line by line?

I need something like this but in java:

(linux file utility)
jeremyt@jeremyt-lt:~/Documents> file test-win.txt
test-win.txt: ASCII text, with CRLF line terminators
jeremyt@jeremyt-lt:~/Documents> file test-mac.txt
test-mac.txt: ASCII text, with CR line terminators
jeremyt@jeremyt-lt:~/Documents> file test-unix.txt
test-unix.txt: ASCII text
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure why you don't want to read the file line by line, but I'd read it character by character and count both newlines and carriage returns. The ratio of both would be an indication which file is which.

Or you could use something like Ant's <crlf> task that converts the file to whichever line ending you prefer.
 
Kudret Serin
Ranch Hand
Posts: 167
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

How can I get the result, if I run the file command with Runtime.exec()?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd start by reading this article about the care and feeding of Runtime.exe.
 
Kudret Serin
Ranch Hand
Posts: 167
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much ;)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!