我遇到了编写代码时将大写字母从一个文件转换为小写字母的问题另一个。当代码运行一些名为inputtext.txt的文本文件时,它会创建输出文件,但不会转换大写文本。Java代码复制所有文本,同时将大写字母从一个文本文件转换为另一个文本文件中的小写字母
import java.io.*;
public class TextFile {
public static void main (String[] args) throws IOException {
// Assume default encoding.
// The name of the file to open for reading.
File filein = new File("inputtext.txt");
// The name of the file to open for writing.
File fileout = new File("outputtext.txt");
char CharCounter = 0;
BufferedReader in = (new BufferedReader(new FileReader(filein)));
PrintWriter out = (new PrintWriter(new FileWriter(fileout)));
int z;
while ((z = in.read()) != -1){
if (Character.isUpperCase(z)){
Character.toLowerCase(z);
}
out.write(z);
}
// Always close files.
in.close();
out.close();
}
}
2017-06-21
Rana
+0
** Character.toLowerCase(INT)** **实际收益**东西太多我愿意进一步澄清,并且这不是C/C++,我们在这里讨论,您可能希望方法改变**原始类型的值** –
+0
在将行写入输出文件之前,逐行读取并在您的行上调用String.toLowerCase。 –
+0
请详细说明,因为我对java和编程相当新颖@ShayHAned –