我在一个标签{{{{{{{ 1}}分隔文件。换行符显示为预期的," \ n"但是,进纸也用作内部场分隔符。例如:
\r\f
使用Java我只有在将\f
设置为\t
后才能删除换页符 - 对于CR / LF或COL_1 COL_2 COL_3 COL_4
1 A\fB C\fD 2
,然后使用{{1}读取文件}检查line.separator
:
\r
\r\f
的默认设置似乎是" \ n"作为两个字符。我可以删除FileReader.read()
,但现在我必须编写另一种方法来将'\n'
更改为" \ n"并重置private void fixMe() throws Exception{
FileReader in = new FileReader("C:\\somefile.txt");
FileReader out = new FileReader("C:\\someotherfile.txt");
Syetem.setProperty("line.separator","\r");
try {
int c;
while (( c = in.read()) != -1 ) {
if ( c != '\n' ) {
out.write(c);
}
}
}
...
作为方法的一部分。有一个更好的方法吗?我想使用扫描仪,但解决方案指向再次重置in.read
设置,我想避免。
答案 0 :(得分:0)
更好地阅读所有文件内容,然后在保存到所需位置后删除" \ n和\ r \ n和\ f"
参见示例:
String content = new String(Files.readAllBytes(Paths.get("path-to-file")));
String processedContent = content.replaceAll("\\n|\\r\\n|\\f", "");
答案 1 :(得分:0)
根据您的问题,如果它是CRLF \ r \ f,您似乎想跳过文件中的换行符'\ f'而不跳过,因此跟踪上次读取的字符可能会解决您的问题。
runTimeCommand
-annotation "Print the word \"Hello\""
-command ("print \"foo\"")
MySave;
nameCommand
-annotation "Print the word \"Hello\""
-command ("print \"foo\"")
MySaveNamed;
buildFileMenu();
menuItem -e -c "MySave" "MayaWindow|mainFileMenu|saveItem";
iconTextButton -e -c "MySave2" openSceneButton;
hotkey -keyShortcut "s" -ctl -name ("MySaveNamed");