파일 크기가 중요한 곳에서 뭔가를해야합니다. 두 번째는 짧은오고 왜이 이상한 결과Ruby는 라인 읽기를 위해 다른 파일 크기를 읽습니다.
이original size 20121
Totals 20061
같은
filename = "testThis.txt"
total_chars = 0
file = File.new(filename, "r")
file_for_writing = nil
while (line = file.gets)
total_chars += line.length
end
puts "original size #{File.size(filename)}"
puts "Totals #{total_chars}"
를 생산?
편집 : 답변자의 직감이 옳습니다. 테스트 파일의 내용은 60 줄입니다. 이 줄을 바꾸면
total_chars += line.length + 1
완벽하게 작동합니다. 그러나 * nix에서는이 변경이 잘못되었을 수 있습니까?
편집 : 후속 조치는 현재 here입니다. 감사!
수정, 그 수정은 windoze에서만 작동합니다. – workmad3