java.io.File file = new java.io.File(file_name);
java.io.FileInputStream fis = new java.io.FileInputStream(file);
String str_tz="insert into XX values(?,?);";
PreparedStatement stmt_tz=conn.prepareStatement(str_tz);
stmt.setString(1,id);
stmt.setBinaryStream(2,fis,(int)file_up.length());
stmt.executeUpdate();
stmt.close();
保存图片没有问题,保存空白doc也没有问题
保存有中文内容的doc就出现乱码
应该是FileInputStream读取中文的问题?
不知道该怎么解决了!
------解决方案--------------------
改成byte试试
- Java code
public static String getCode(byte[] bs) { ImageIcon icon = new ImageIcon(bs, "hello"); Object ob = JOptionPane.showInputDialog((Component) null, "", "输入验证码", JOptionPane.INFORMATION_MESSAGE, icon, null, ""); return (String) ob; } public static void File() throws Exception { File file = new File("F:\\psp\\picture\\she\\hebe.jpg"); FileInputStream out = new FileInputStream(file); byte[] bs = new byte[out.available()]; out.read(bs); System.out.println(getCode(bs)); }
------解决方案--------------------
保存的word编码与进入保存数据库的编码要做转换。