我正在使用以下代码读取CSV文件:
2019-02-01T15:06:02.138+0200 INFO user.dir=C:\projects\eclipse_workspace\RFIDGates
Feb 01, 2019 3:06:02 PM com.microsoft.sqlserver.jdbc.AuthenticationJNI <clinit>
WARNING: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
2019-02-01T15:06:16.927+0200 ERROR Get conn exception
com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication. ClientConnectionId:68da04a3-d764-4c5d-a7ad-addd324db006
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2670) ~[mssql-jdbc-6.4.0.jre8.jar:?]
at com.microsoft.sqlserver.jdbc.AuthenticationJNI.<init>(AuthenticationJNI.java:79) ~[mssql-jdbc-6.4.0.jre8.jar:?]
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3381) ~[mssql-jdbc-6.4.0.jre8.jar:?]
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$100(SQLServerConnection.java:85) ~[mssql-jdbc-6.4.0.jre8.jar:?]
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3373) ~[mssql-jdbc-6.4.0.jre8.jar:?]
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7344) ~[mssql-jdbc-6.4.0.jre8.jar:?]
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2713) ~[mssql-jdbc-6.4.0.jre8.jar:?]
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2261) ~[mssql-jdbc-6.4.0.jre8.jar:?]
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1921) ~[mssql-jdbc-6.4.0.jre8.jar:?]
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1762) ~[mssql-jdbc-6.4.0.jre8.jar:?]
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1077) ~[mssql-jdbc-6.4.0.jre8.jar:?]
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:623) ~[mssql-jdbc-6.4.0.jre8.jar:?]
at java.sql.DriverManager.getConnection(DriverManager.java:664) ~[?:1.8.0_171]
at java.sql.DriverManager.getConnection(DriverManager.java:247) ~[?:1.8.0_171]
at com.kpv.rfid.db.ConnectMSSQLServer.main(ConnectMSSQLServer.java:270) [classes/:?]
Caused by: java.lang.UnsatisfiedLinkError: no sqljdbc_auth in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) ~[?:1.8.0_171]
at java.lang.Runtime.loadLibrary0(Runtime.java:870) ~[?:1.8.0_171]
at java.lang.System.loadLibrary(System.java:1122) ~[?:1.8.0_171]
at com.microsoft.sqlserver.jdbc.AuthenticationJNI.<clinit>(AuthenticationJNI.java:54) ~[mssql-jdbc-6.4.0.jre8.jar:?]
... 13 more
CSV文件的列中有一个字符using (StreamReader readfile = new StreamReader(FilePath, Encoding.GetEncoding("iso-8859-1")))
{
// some code will go here
}
。在输出中将其转换为œ
。我怎样才能得到这种操作编码正确,以便在输出我会得到相同的œ字符不是一个问号。
答案 0 :(得分:2)
这是一个编码问题。许多非Unicode编码要么不完整,要么将许多字符转换为“?”,或者在不同平台上的行为略有不同。考虑使用UTF-8或UTF-16作为默认值。至少,如果可以的话。
“ windows-1252”是“ ISO-8859-1”的超集。尝试使用Encoding.GetEncoding(1252)
。
演示:
public static void Main()
{
System.IO.File.AppendAllText("test","œ", System.Text.Encoding.GetEncoding(1252));
var content = System.IO.File.ReadAllText("test", System.Text.Encoding.GetEncoding(1252));
Console.WriteLine(content);
}
答案 1 :(得分:0)
iso-8859-15 字符集包含这些符号,Windows-1252 代码页也是如此。但是,请注意,8859-15 重新定义了 8859-1 中的其他六个很少使用(或 ASCII 重复)字符,但 Windows 1252 也是如此。快速网络搜索将揭示这些差异。