JAVA的程序java.io.IOException出错是啥??
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVA的程序java.io.IOException出错是啥??相关的知识,希望对你有一定的参考价值。
Running with storage root DefaultColorPhone客户端 : 192.168.0.35java.io.IOException: error 10054 during TCP read at com.sun.midp.io.j2me.socket.Protocol.nonBufferedRead(+7) at com.sun.midp.io.BufferedConnectionAdapter.readBytes(+39) at com.sun.midp.io.BaseInputStream.read(+39) at com.sun.midp.io.BaseInputStream.read(+10) at java.io.DataInputStream.read(+7) at java.io.DataInputStream.readUnsignedShort(+4) at java.io.DataInputStream.readUTF(+6) at java.io.DataInputStream.readUTF(+4) at M_Server3.startApp(+57) at javax.microedition.midlet.MIDletProxy.startApp(+7) at com.sun.midp.midlet.Scheduler.schedule(+270) at com.sun.midp.main.Main.runLocalClass(+28) at com.sun.midp.main.Main.main(+116)Execution completed.991273 bytecodes executed697 thread switches740 classes in the system (including system classes)5206 dynamic objects allocated (144372 bytes)2 garbage collections (117168 bytes collected)
io 就是 input output 即 读 与 写。你这里是与客户端连接错误。对方可能关闭了端口。导致你无法读取 参考技术A 跟服务器失去连接 参考技术B 在读取数据的过程中,网络断了
java中怎么实现ftp文件传输
package com.quantongfu.ftp.ftp;import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.List;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.log4j.Logger;
import org.apache.log4j.net.SocketServer;
import com.quantongfu.conf.FtpConf;
/**
* @项目名称: telinSyslog
* @文件名称: Ftp.java
* @创建日期:2015年9月14日 下午3:22:08
* @功能描述:ftp实体类,用于连接,上传
* @修订记录:
*/
public class Ftp
private static Logger logger = Logger.getLogger(Ftp.class);
private FTPClient ftp;
/**
*
* @param path
* 上传到ftp服务器哪个路径下
* @param addr
* 地址
* @param port
* 端口号
* @param username
* 用户名
* @param password
* 密码
* @return
* @throws Exception
*/
public boolean connect() throws Exception
boolean result = false;
ftp = new FTPClient();
int reply;
ftp.connect(FtpConf.FTP_HOST, FtpConf.FTP_PORT);
ftp.login(FtpConf.FTP_USER_NAME, FtpConf.FTP_PASSWORD);
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
ftp.setDataTimeout(60000);
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply))
ftp.disconnect();
return result;
if (FtpConf.IS_FTP_DIRECTORY)
ftp.changeWorkingDirectory(FtpConf.FTP_DIRECTORY);
result = true;
return result;
/**
*
* @param files
* 上传的文件
* @throws Exception
*/
public boolean upload(File file) throws IOException
FileInputStream input = null;
try
input = new FileInputStream(file);
boolean b = ftp.storeFile(file.getName() + ".tmp", input);
if (b)
b = ftp.rename(file.getName() + ".tmp", file.getName());
return b;
catch (Exception e)
e.printStackTrace();
return false;
finally
if (input != null)
input.close();
/**
*
* @param files
* 上传的文件
* @throws Exception
*/
public boolean upload(ServerSocket server, File file) throws Exception
FileInputStream input = null;
try
if (!file.exists())
return true;
input = new FileInputStream(file);
boolean b = ftp.storeFile(server, file.getName() + ".tmp", input);
if (b)
b = ftp.rename(file.getName() + ".tmp", file.getName());
if (b)
file.delete();
return b;
catch (Exception e)
logger.error("ftp error" + e.getMessage());
return false;
finally
if (input != null)
try
input.close();
catch (IOException e)
e.printStackTrace();
/*断开连接*/
public void disConnect()
try
if (ftp != null)
ftp.disconnect();
catch (IOException e)
e.printStackTrace();
/*获取连接*/
public static Ftp getFtp()
Ftp ftp = new Ftp();
try
ftp.connect();
catch (Exception e)
logger.error("FTP连接异常" + e.getMessage());
e.printStackTrace();
return ftp;
/*重连*/
public Ftp reconnect()
disConnect();
return getFtp();
使用Apache FtpClient jar包,获取jar : http://commons.apache.org/net/
参考技术A 直接上代码:package com.sinosoft.sepmis.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
/**
* Java自带的API对FTP的操作
* @Title:Ftp.java
* @author: shanhongzhi
*/
public class FtpUtil
/**
* Description: 向FTP服务器上传文件
* @param url FTP服务器hostname
* @param port FTP服务器端口,如果默认端口请写-1
* @param username FTP登录账号
* @param password FTP登录密码
* @param path FTP服务器保存目录
* @param filename 上传到FTP服务器上的文件名
* @param input 输入流
* @return 成功返回true,否则返回false
*/
public static boolean uploadFile(String url, int port, String username, String password, String path,
String filename, InputStream input) throws Exception
boolean success = false;
FTPClient ftp = new FTPClient();
try
int reply;
// 连接FTP服务器
if (port > -1)
ftp.connect(url, port);
else
ftp.connect(url);
// 登录FTP
ftp.login(username, password);
reply = ftp.getReplyCode();
System.out.println(reply);
if (!FTPReply.isPositiveCompletion(reply))
ftp.disconnect();
return success;
ftp.changeWorkingDirectory(path);
ftp.storeFile(filename, input);
input.close();
ftp.logout();
success = true;
catch (IOException e)
success = false;
throw e;
finally
if (ftp.isConnected())
try
ftp.disconnect();
catch (IOException e)
throw e;
return success;
public static void main(String agrs[])
try
File file = new File("E:\\1.txt");
FileInputStream in = new FileInputStream(file);
/*
* 使用默认的端口号、用户名、密码以及根目录连接FTP服务器
*/
//返回true上传成功,否则上传失败
// FtpUtil.uploadFile("192.168.61.209", -22, "instiaci", "instiaci", "/db2home/instiaci/personal/shanhz","2.txt",in);
//“sinopipi/IC/tkk"目录要是已经存在的目录
FtpUtil.uploadFile("192.168.61.104", 22, "administrator", "123456", "/sinopipi/IC","6.txt",in);
catch (Exception e)
e.printStackTrace();
说明:所需的jar包是commons-net-2.0.jar本回答被提问者采纳
以上是关于JAVA的程序java.io.IOException出错是啥??的主要内容,如果未能解决你的问题,请参考以下文章
Android android.view.InflateException Binary XML 文件第 16 行:膨胀类片段时出错