我目前有代码行:
ResultSet RS = cs.executeQuery();
....
FileOutputStream outFile = new FileOutputStream(file, false);
while(RS.next()) {
outFile.write(RS.getString(1));
}
结果集中只有一列。我收到的错误是RS.getString(1)必须是int。
答案 0 :(得分:2)
FileOutputStream#write需要int
值。您可以在此使用PrintWriter
,而不是overloaded write
method for writing String
values:
PrintWriter writer = new PrintWriter(new FileOutputStream(file, false));
writer.write(...);
或使用println
在新行上写下每个String
writer.println(...);
答案 1 :(得分:0)
请尝试一下。
public static void main(String[] arg) throws IOException{
File file=new File("C:\\file.txt");
String text="myText";
FileOutputStream fileOutputStream=new FileOutputStream(file);
fileOutputStream.write(text.getBytes());
fileOutputStream.close();
}