Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何读取文本文件中的字符并获取字符长度?_Java_File Io - Fatal编程技术网

Java 如何读取文本文件中的字符并获取字符长度?

Java 如何读取文本文件中的字符并获取字符长度?,java,file-io,Java,File Io,我有一个名为“text_in.txt”的java文本文件,其中包含 IDESOFMARCH 这是11个字符的长度,我如何找到这个文件的长度,并在H的末尾添加一个“X”字符,以便将文本分成两个字符的块,每个块用于RSA加密/解密 示例:MA-RC-HX的ID-ES 我有一个main()从rsa.java文件(文件、私钥、公钥)调用encrypt方法 文件包含“text_in.txt”和“text_out.txt”以及打开这两个文件的布尔值true 主要原因是: public void encry

我有一个名为“text_in.txt”的java文本文件,其中包含

IDESOFMARCH
这是11个字符的长度,我如何找到这个文件的长度,并在H的末尾添加一个“X”字符,以便将文本分成两个字符的块,每个块用于RSA加密/解密

示例:
MA-RC-HX的ID-ES

我有一个main()从rsa.java文件(文件、私钥、公钥)调用encrypt方法

文件包含“text_in.txt”和“text_out.txt”以及打开这两个文件的布尔值true

主要原因是:

public void encrypt(FileInOut files, int e, int n) {



//Get the in file length and add a 'X' if uneven character blocks
    if((files.length() % 2) == 1)
      files.write("X");

//Print a 0 in the encrypted file to represent the end of a line
    if(files != char)
      files.write("0");

好吧,从我这里借用一个答案


为什么不使用有效的加密填充呢?比自己做要可靠得多。可能是Thank you@WillShackleford的复制品这很有帮助,我以前试过搜索,但找不到。
public void encrypt(FileInOut files, int e, int n) {



//Get the in file length and add a 'X' if uneven character blocks
    if((files.length() % 2) == 1)
      files.write("X");

//Print a 0 in the encrypted file to represent the end of a line
    if(files != char)
      files.write("0");
String str = new String(Files.readAllBytes(Paths.get("text_in.txt")));
int len = str.length();