我在数据库中有很多这样的字符串:"\\LDDESKTOP\news\1455Bloomberg Document # 180784.txt"
。我想在最后一个斜杠之后获取文件名。
我只是以正常方式这样做:
str.substring(str.lastIndexOf("\\")+1)
但它不起作用,因为单斜杠用于更改含义。java中有没有办法像python一样告诉编译器将其视为像这样的纯字符串,str=r'.......'
.
或者如何将字符串更改为"\\\\LDDESKTOP\\news\\1455Bloomberg Document # 180784.txt"
. 所以我可以将它传递给 File Object 来读取这个文件。
我该怎么做?或其他解决此问题的方法。
谢谢。
news 表中名为 path(varchar(150)) 的列是这样的“\LDDESKTOP\news\1362Bloomberg Document #180691.txt”
我在路径上做了一个正常的选择。
编码 :
public List<String> getNewsFileName(String startTime,String endTime) {
List<String> newsFileNames = new ArrayList<String>();
String tableName = ConfigFile.getConfig("configuration.txt","SQLServerTable");
String sql = "select Path from [" + tableName + "] where localtime >= '" + startTime + "' and localtime <= '" + endTime + "'";
try {
if(connection==null) {
InvertedIndex.logger.log(Level.SEVERE, "Database connection has not been initialized");
System.exit(-1);
}
stmt=connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
String path=rs.getString(1);
newsFileNames.add(path);
}
} catch (SQLException e) {
InvertedIndex.logger.log(Level.SEVERE,"Fail to store news");
}
return newsFileNames;
}