gpt4 book ai didi

java - 文件输出流有问题

转载 作者:行者123 更新时间:2023-12-02 12:10:48 24 4
gpt4 key购买 nike

所以我收到一条错误消息:

java.io.FileNotFoundException: drscqei<@.txt (The filename, directory name, 
or volume label syntax is incorrect)

at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileWriter.<init>(Unknown Source)
at ch1.User.makeUser(User.java:205)
at ch1.helloworld.main(helloworld.java:94)

ma​​keUser函数包括以下内容:

public static User makeUser(String fn, String ln, String un, String pw, String cpw, String dob) {
if (pw.equals(cpw)) {
System.out.println("pass is same as confirm.");
if (containsNumber(pw) && charLength(pw) && charLength(un) && !(containsInvalidSymbol(un))) {
System.out.println(
"pw has an uppercase and lower and doesnt have any symbols and length of un and pw are greater than 5 and less than 50.");
encrypt(fn, ln, un, pw, dob);
File f = new File(encryptedUser + ".txt");
try {
FileWriter fw = new FileWriter(f);
fw.write(encryptedFn + "," + encryptedLn + "," + encryptedUser + "," + encryptedPass + ","
+ encryptedDob);
fw.flush();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
return new User(fn, encryptedLn, encryptedUser, encryptedPass, encryptedDob);
} else {
return null;
}
} else {
return null;
}

}

加密方法只是使用凯撒密码对字符串进行加密

I know that Caesar cipher isn't the best type of encryption method, although, currently I'm just trying to make it dummy proof. the encryption method is as follows:

public static void encrypt(String fn, String ln, String un, String pw, String dob) {

int shift = 10;
for (int x = 0; x < un.length(); x++) {
char c = (char) (un.charAt(x) + shift);
if (c > 'z') {
encryptedUser += (char) ((un.charAt(x) - 26) + shift);
} else {
encryptedUser += (char) (un.charAt(x) + shift);
}
}
}

我收到错误的 helloworld 类具有以下代码:

            boolean signUpScreen = true;
do {
int s = JOptionPane.showOptionDialog(null, signUp, "Sign Up", JOptionPane.OK_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE, null, Enter_Cancel, Enter_Cancel[0]);
if (s == JOptionPane.OK_OPTION) {

User.eraseEncryptions();

User sUser = User.makeUser(signUpfn.getText(), signUpln.getText(), signUpUser.getText(),
signUpPass.getText(), signUpCPass.getText(), signUpDob.getText());
if (sUser == null) {
JOptionPane.showMessageDialog(null,
"Sorry, something went wrong. please check that you have filled in all the text fields and that your password is the same as your confirm password.",
"Error", JOptionPane.PLAIN_MESSAGE);
} else {
JOptionPane.showMessageDialog(null,
"Success! You have created a new account! welcome " + User.fn, "Account Created",
JOptionPane.PLAIN_MESSAGE);
signUpScreen = false;
}
} else {
signUpScreen = false;
}
} while (signUpScreen);

signUp 只是一个包含 JTextFields 的 JPanel。我的问题是为什么我会收到此错误,我想概括一下我必须做的事情,以便我可以自己解决这个问题,但如果不可能,那么解决方案就可以了。感谢您抽出时间。

最佳答案

您正在运行的操作系统不允许使用类似 drscqei<@.txt 的名称。以 Windows 为例 doesn't allow <

关于java - 文件输出流有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46565728/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com