Apache Ftp Server 中文目录,中文文件名,IE访问乱码解决

Apache Ftp Server,目前是1.0.4,非常好的纯Java Ftp服务器,既可以直接提供FTP服务,有可以嵌入到程序里。

 

如果Ftp服务器提供的内容,有中文目录,文件名,XP下IE访问会出现一些错误。

如果IE的选项->高级里 为Ftp站点启用文件夹视图选项

没有选中,这时显示的是Html页面,但中文显示是乱码,强行指定编码为Utf8,则显示正常,但无法下载;

该选项选中,这时是文件夹方式显示Ftp服务器内容,选中文件夹后右键复制到文件夹,会复制出错,但用复制,然后粘贴到指定位置的方式可以正常复制。

使用windows带的ftp.exe访问站点,遇到中文也会出现错误。

但如果用流行的ftp客户端,比如FlashFXP就一切正常。

 

这说明XP 下IE的Ftp支持有bug。

但用户一般不用Ftp客户端,为了迁就IE,只有对ApacheFtpServer修改,通过查资料,XP下用的编码是GBK,只要把Apache FtpServer代码中处理编码的地方由国际标准UTF8编码改为迁就Xp下IE的GBK编码即可完成。

 

 

具体修改 

 


org.apache.ftpserver.command.impl包里OPTS_UTF8.java
将 
session.write(LocalizedFtpReply.translate(session, request, context, FtpReply.REPLY_200_CO

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
在Java中使用Zip压缩中文文件名可能会出现乱码的问题,这是因为Zip文件格式默认使用的是ASCII编码,而中文字符需要使用其他编码方式进行处理。解决这个问题的方法有两种: 1. 使用Apache Commons Compress库 可以使用Apache Commons Compress库来压缩文件,这个库支持多种编码方式,可以解决中文文件名乱码的问题。示例代码如下: ```java import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; import org.apache.commons.compress.utils.IOUtils; import java.io.*; public class ZipUtil { public static void zip(String sourcePath, String destPath) throws IOException { FileOutputStream fos = new FileOutputStream(destPath); ZipArchiveOutputStream zos = new ZipArchiveOutputStream(fos); File file = new File(sourcePath); String basePath = file.getParent(); compress(file, zos, basePath); zos.close(); fos.close(); } private static void compress(File file, ZipArchiveOutputStream zos, String basePath) throws IOException { if (file.isDirectory()) { File[] files = file.listFiles(); if (files.length == 0) { String path = file.getPath().substring(basePath.length() + 1) + "/"; ArchiveEntry entry = zos.createArchiveEntry(new File(file.getPath()), path); zos.putArchiveEntry(entry); zos.closeArchiveEntry(); } else { for (File f : files) { compress(f, zos, basePath); } } } else { String path = file.getPath().substring(basePath.length() + 1); ArchiveEntry entry = zos.createArchiveEntry(new File(file.getPath()), path); zos.putArchiveEntry(entry); InputStream is = new FileInputStream(file); IOUtils.copy(is, zos); is.close(); zos.closeArchiveEntry(); } } } ``` 2. 使用Java的ZipOutputStream类 Java中自带的ZipOutputStream类也可以用于压缩文件,但是需要手动设置编码方式,示例代码如下: ```java import java.io.*; import java.nio.charset.Charset; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class ZipUtil { private static final int BUFFER_SIZE = 2 * 1024; public static void zip(String sourcePath, String destPath) throws IOException { FileOutputStream fos = new FileOutputStream(destPath); ZipOutputStream zos = new ZipOutputStream(fos, Charset.forName("GBK")); File file = new File(sourcePath); String basePath = file.getParent(); compress(file, zos, basePath); zos.close(); fos.close(); } private static void compress(File file, ZipOutputStream zos, String basePath) throws IOException { if (file.isDirectory()) { File[] files = file.listFiles(); if (files.length == 0) { String path = file.getPath().substring(basePath.length() + 1) + "/"; ZipEntry entry = new ZipEntry(path); zos.putNextEntry(entry); zos.closeEntry(); } else { for (File f : files) { compress(f, zos, basePath); } } } else { String path = file.getPath().substring(basePath.length() + 1); ZipEntry entry = new ZipEntry(path); zos.putNextEntry(entry); InputStream is = new FileInputStream(file); byte[] buffer = new byte[BUFFER_SIZE]; int len; while ((len = is.read(buffer)) != -1) { zos.write(buffer, 0, len); } is.close(); zos.closeEntry(); } } } ``` 以上两种方法都可以解决中文文件名乱码的问题,具体使用哪一种方法可以根据实际需要选择。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值