我要写一个文本文件通过ftp上传,他的要求如下:
文件采用ASCII文本格式,文件体中一行作为一条记录,每一条记录代表用户订购的一个业务,每条记录的属性(8个)值按顺序排列,各属性间使用‘\t’分隔,各条记录之间用换行符作为分割我想问一下"文件采用ASCII文本格式"是什么意思??我写了一个方法,主要是把每个string转换成ASCII再写入文本,不知对不对??如果不对该怎么写?谢谢
public void writeTxt(String strP,String strC, String strD, String str1, String str2, String str3, String str4, String str5)
{
try
{
byte[] F = "\t".getBytes("US-ASCII"); byte[] N = "\r\n".getBytes("US-ASCII");
System.out.println(F);
System.out.println(N); if(strP != null)
{
byte[] P = strP.getBytes("US-ASCII");
bos.write(P);
System.out.println(P);
}
bos.write(F);
if(strC != null)
{
byte[] C = strC.getBytes("US-ASCII");
bos.write(C);
}
bos.write(F); if(strD != null)
{
byte[] D = strD.getBytes("US-ASCII");
bos.write(D);
}
else
{
byte[] D = strD.getBytes("US-ASCII");
bos.write(D);
}
bos.write(F); if(str1 != null)
{
byte[] s1 = str1.getBytes("US-ASCII");
bos.write(s1);
}
bos.write(F);
if(str2 != null)
{
byte[] s2 = str2.getBytes("US-ASCII");
bos.write(s2);
}
bos.write(F);
if(str3 != null)
{
byte[] s3 = str3.getBytes("US-ASCII");
bos.write(s3);
}
bos.write(F);
if(str4 != null)
{
byte[] s4 = str4.getBytes("US-ASCII");
bos.write(s4);
}
bos.write(F);
if(str5 != null)
{
byte[] s5 = str5.getBytes("US-ASCII");
bos.write(s5);
}
bos.write(N); System.out.println(strP+", "+strC+", "+strD); }catch(Exception e)
{
System.out.print("写入文件失败: ");
System.out.println(e.getMessage());
}
}
文件采用ASCII文本格式,文件体中一行作为一条记录,每一条记录代表用户订购的一个业务,每条记录的属性(8个)值按顺序排列,各属性间使用‘\t’分隔,各条记录之间用换行符作为分割我想问一下"文件采用ASCII文本格式"是什么意思??我写了一个方法,主要是把每个string转换成ASCII再写入文本,不知对不对??如果不对该怎么写?谢谢
public void writeTxt(String strP,String strC, String strD, String str1, String str2, String str3, String str4, String str5)
{
try
{
byte[] F = "\t".getBytes("US-ASCII"); byte[] N = "\r\n".getBytes("US-ASCII");
System.out.println(F);
System.out.println(N); if(strP != null)
{
byte[] P = strP.getBytes("US-ASCII");
bos.write(P);
System.out.println(P);
}
bos.write(F);
if(strC != null)
{
byte[] C = strC.getBytes("US-ASCII");
bos.write(C);
}
bos.write(F); if(strD != null)
{
byte[] D = strD.getBytes("US-ASCII");
bos.write(D);
}
else
{
byte[] D = strD.getBytes("US-ASCII");
bos.write(D);
}
bos.write(F); if(str1 != null)
{
byte[] s1 = str1.getBytes("US-ASCII");
bos.write(s1);
}
bos.write(F);
if(str2 != null)
{
byte[] s2 = str2.getBytes("US-ASCII");
bos.write(s2);
}
bos.write(F);
if(str3 != null)
{
byte[] s3 = str3.getBytes("US-ASCII");
bos.write(s3);
}
bos.write(F);
if(str4 != null)
{
byte[] s4 = str4.getBytes("US-ASCII");
bos.write(s4);
}
bos.write(F);
if(str5 != null)
{
byte[] s5 = str5.getBytes("US-ASCII");
bos.write(s5);
}
bos.write(N); System.out.println(strP+", "+strC+", "+strD); }catch(Exception e)
{
System.out.print("写入文件失败: ");
System.out.println(e.getMessage());
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货