回车和换行窗口和 Linux java 应用程序 [英] Carriage Return and Line Feed windows and Linux java application

查看:46
本文介绍了回车和换行窗口和 Linux java 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个集成测试应用程序,这就是我在测试用例中所做的,我读取存储在 cvs 中的测试输入文件,将其写入文件系统中的文件,应用程序轮询文件的目录,处理它并创建输出文件,然后轮询输出文件的目录,如果两个文件内容相等,则测试用例成功(我正在将输入文件和输出文件读入字符串并进行比较).

I am working on a integration test application, this is what I am doing in the test case, I read a test input file,which is stored in the cvs , write it to a file in the file system,the application polls the directory for the file, processes it and creates the output file, and I poll the directory for the output file, test case is successful if the both the file contents are equal(I am reading the both input files and output files into strings and comparing them).

问题是这个测试用例在 linux 系统中运行时失败,原因是存储在 cvs 中的文件是从包含 CRLF 作为行终止符的 Windows 系统签入的,而生成的输出文件具有行终止为 CR,现在当我读取这些文件并逐个字符比较它们时,它们不匹配.

The problem is this test case fails when its runs in a linux system, the reason being the file which is stored in the cvs was checked in from a windows system which contains CRLF as the line terminations whereas the output file generated has the line terminations as CR,now when I read these files and compare them character by character, they are having a mismatch.

有人可以帮忙吗?

推荐答案

您可以使用 System.getProperty("line.separator") 来检查主机操作系统的行分隔符

由于您使用的是文本文件,您还可以逐行比较文件内容.检查 LineNumberReader.readLine() .

Since you're using text files, you can also compare the file contents line by line. Check LineNumberReader.readLine() for that.

这篇关于回车和换行窗口和 Linux java 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆