Error Reading From Inputstream Java.io.ioexception
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up IOException: Read Error up vote 0 down vote favorite If you want more info on the error, the full source can be downloaded here Hey, I'm reading an ini file using java.util.Properties; and I've run into a strange issue. When I try to load a specific file, the thing spits out this strange exception that I've been trying for about a day to eliminate. java.io.IOException: Read error at java.io.FileInputStream.readBytes(Native Method) at java.io.FileInputStream.read(Unknown Source) at java.util.Properties$LineReader.readLine(Unknown Source) at java.util.Properties.load0(Unknown Source) at java.util.Properties.load(Unknown Source) at IniReader.load(IniReader.java:20) at plane.
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up java.sql.SQLException: Error reading from InputStream http://stackoverflow.com/questions/5684250/ioexception-read-error java.io.IOException up vote 1 down vote favorite i m using Struts2 for creating registration form , i want to store the image path in database and then want to retrieve the image in jsp. so in RegistrationService class i uses fileinput stream ,so that path get placed in database. but i get an error. java.sql.SQLException: Error reading from InputStream java.io.IOException RegistrationService.java FileInputStream fis1 = new http://stackoverflow.com/questions/31876958/java-sql-sqlexception-error-reading-from-inputstream-java-io-ioexception FileInputStream(registration.getResume_attachment()); p.setBinaryStream(25,fis1,fis1.available()); FileOutputStream fos_resume=new FileOutputStream(registration.getResume_attachment()); byte buffer[]=new byte[1024]; int read=0; while((read=fis1.read(buffer, 0, 1024))!=-1){ fos_resume.write(buffer); } fis1.close(); fos_resume.close(); Registration.java public class Registration{ private String resume_attachment; private String photo_attachment; private String pre_company; //getter and setter java sql share|improve this question edited Aug 7 '15 at 12:28 Roman C 34.3k133559 asked Aug 7 '15 at 11:45 sufiyan ali 4118 1 Add the complete stacktrace please. –Jens Aug 7 '15 at 11:48 @sufiyan the resume_attachment should be File type not String type :) mkyong.com/struts2/struts-2-file-upload-example –goodyzain Aug 7 '15 at 12:41 add a comment| active oldest votes Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook. Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Browse other questions tagged java sql or ask your own question. asked 1 year ago viewed 152 times Related 2069Create ArrayList from array2278Read/convert an InputStream to a String96Is it possi
an error condition where executeUpdate() gives an exception if the InputStream is closed too early. The program in the previous tutorial worked nicely. But if you make a mistake by placing the bodyIn.close() statement before ps.executeUpdate(), you will get an IOException when ps.executeUpdate() is called. The reason is simple, reading of binary data from the InputStream is done at the time of executeUpdate() call, not before. Here is a test program: /* MySqlBlobSetBinaryStreamError.java - Copyright (c) 2015, HerongYang.com, All Rights Reserved. */ import java.io.*; import java.sql.*; public class MySqlBlobSetBinaryStreamError { public static void main(String [] args) { Connection con = null; try { com.mysql.jdbc.jdbc2.optional.MysqlDataSource ds = new com.mysql.jdbc.jdbc2.optional.MysqlDataSource(); ds.setServerName("localhost"); ds.setPortNumber(3306); ds.setDatabaseName("HerongDB"); ds.setUser("Herong"); ds.setPassword("TopSecret"); con = ds.getConnection(); // Deleting the record for re-testing String subject = "Test of setBinaryStream() method error"; Statement sta = con.createStatement(); sta.executeUpdate("DELETE FROM Image WHERE Subject = '" +subject+"'"); // Inserting CLOB value with PreparedStatement.setBinaryStream() PreparedStatement ps = con.prepareStatement( "INSERT INTO Image (Subject, Body) VALUES (?,?)"); ps.setString(1, subject); InputStream bodyIn = new FileInputStream("MySqlBlobSetBinaryStream.class"); File fileIn = new File("MySqlBlobSetBinaryStream.class"); ps.setBinaryStream(2, bodyIn, (int) fileIn.length()); // Error - Closing the InputStream too early. bodyIn.close(); int count = ps.executeUpdate(); ps.close(); // Retrieving BLOB value with getBytes() sta = con.createStatement(); ResultSet res = sta.executeQuery("SELECT * FROM Image" +" WHERE Subject = '"+subject+"'"); res.next(); System.out.println("The inserted record: "); System.out.println(" Subject = "+res.getString("Subject")); System.out.println(" Body = " +new String(res.getBytes("Body"),0,32)); res.close(); sta.close(); c