我正在尝试读取我的文本文件“ inputFile.txt”,但系统显示以下错误。 谁能帮我解决这个错误?谢谢!
错误:类型不兼容:FileInputStream无法转换为Reader Yylex yy =新的Yylex(fin);
CLIENT -> SERVER: EHLO localhost
2018-08-10 08:45:27 CLIENT -> SERVER: AUTH LOGIN
2018-08-10 08:45:27 CLIENT -> SERVER: <credentials hidden>
2018-08-10 08:45:27 CLIENT -> SERVER: <credentials hidden>
2018-08-10 08:45:28 SMTP ERROR: Password command failed: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbs8534-5.7.14 qnkx1ftXmOKno0nsg7hE8GcJQABBOD5tKdlhHDkafCl07-nac1ZdHuBwSPvackU8MO9HbN534-5.7.14 wL4C9Cjxkmknf0s9OFWkEb0bJ5RT2WhX_jTZWvdW_5dHefiXvEwAYmQz5w7cXSjS3NbZJ5534-5.7.14 f4yqWmEo8j01hu6l2gBy4LIBheFtnm0B5UwvPFDJAyvRzdhhh4BB2Rr6nlUDPAMZCqmr1M534-5.7.14 oC3K4ztm4auxRpObbvxr-g_hSUJjNtEgeW7KvQ2N6MVLPZjBdA> Please log in via534-5.7.14 your web browser and then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 t15-v6sm11430067wrn.34 - gsmtp
SMTP Error: Could not authenticate.
2018-08-10 08:45:28 CLIENT -> SERVER: QUIT
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
答案 0 :(得分:1)
两个java.io.Reader和java.io.FileInputStream不兼容。这是因为FileInputStream使用字节,而Reader是字符流的接口。如果转到https://docs.oracle.com/javase/8/docs/api/java/io/FileInputStream.html,将会看到FileInputStream没有实现Reader。因此,您需要选择使用Reader +他的实现类还是使用FileInputStream。
FileInputStream示例:https://www.mkyong.com/java/how-to-read-file-in-java-fileinputstream/
Reader的一个实现java.io.BufferedReader的示例:How to use Buffered Reader in Java
P.S。请适当关闭所有流。您的fin.close();不应在尝试部分中关闭!
祝你好运!