Java能否做到把取得的有格式文字转化成流,再把这个流转化成有格式文字?如果可以,应该怎么做? talent_marquis (甜菜侯爵) : 我觉得你的两种思路实际上还是一种思路,因为不管格式与文字一起发送,还是分开发送,到达接受端后都要进行格式的解析。只不过在解析的时候可能有两种,一种是边接受边解析,另外就是分段解析或者一次性解析。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果是第一种方法的话,我就必须自己写一个解析格式的类就算我的文字格式仅仅包括字体类型、字体大小、字体颜色,实际操作判断起来仍然是非常繁琐的我想知道Java本身是否就能够支持带格式文字的流化和流的逆转呢? 所有的文字都是字节流,你可以用Socket发送到接收端。流化和逆转都是你程序逻辑要做的事。 但是我查阅Java2学习手册(第二版)发现它里面有一个介绍输入输出串行化的问题,和我说的意图很接近啊(书P363页)但是介绍的很简略,我看不大懂不知道有没有人对串行化这个东东很了解呢? 比如说ll 是有格式的字你写个内部类比如 kk 然后用kk.ll = ll.getText();当你传的时候就可以把所有的传过去了要传类,在接收的时候再专成ll相对的类型就可以了 不知道这样可以不把你的这些文字转化为字节流用socket收发通讯,然后另一端具体的解析。或者用xml文档定义各个含义,然后收发解析。 我自己通过一个折衷的方法解决了,给大家看看我写的分析格式的类 ^ ^import java.util.regex.*;import java.awt.*;class FormatText{ private String formatText=""; private String nickName,fname,content; private String[] resolveText; private int fType,fSize,cR,cG,cB; private Color fColor; public FormatText(){} //文字名称,文字类型,文字大小,文字颜色,正文 public void setFormatText(String nickName,String fName,int fType,int fSize,int cR,int cG,int cB,String content) { formatText=nickName+"╋"+fName+"╋"+fType+"╋"+fSize+"╋"+cR+"╋"+cG+"╋"+cB+"╋"+content; resolveFormatText(); } public String getNickName() { return nickName; } public String getFormatText() { return formatText; } public String getFontName() { return fname; } public int getFontType() { return fType; } public int getFontSize() { return fSize; } public Color getFontColor() { fColor=new Color(cR,cG,cB); return fColor; } public String getTextContent() { return content; } public boolean getFontBold() { if(fType==1 || fType==3) return true; else return false; } public boolean getFotnItalic() { if(fType==2 || fType==3) return true; else return false; } private void resolveFormatText() { resolveText=Pattern.compile("╋").split(formatText,8); nickName=resolveText[0]; fname=resolveText[1]; fType=Integer.parseInt(resolveText[2]); fSize=Integer.parseInt(resolveText[3]); cR=Integer.parseInt(resolveText[4]); cG=Integer.parseInt(resolveText[5]); cB=Integer.parseInt(resolveText[6]); content=resolveText[7]; } } 用swing实现文件的上传和下载功能 为什么我画不出图来?菜鸟提问 一个字符串截取的问题 如何查看windows中JAVA SDK的版本 在两个不同的数组中提取不同的部分 100分 请问学习JAVA的过程,先学--?然后学--?再学--?最后学--? -->java高手! 急! 如何得到当前鼠标的位置? weblogic连sql数据库出错 新手最简单问题 我的24点算法,希望大家执正 为什么我的JWindow实例w只能隐藏窗口,不能退出程序
就算我的文字格式仅仅包括字体类型、字体大小、字体颜色,实际操作判断起来仍然是非常繁琐的我想知道Java本身是否就能够支持带格式文字的流化和流的逆转呢?
但是介绍的很简略,我看不大懂
不知道有没有人对串行化这个东东很了解呢?
ll 是有格式的字
你写个内部类
比如 kk
然后用
kk.ll = ll.getText();
当你传的时候就可以把所有的传过去了
要传类,在接收的时候再专成ll相对的类型就可以了
把你的这些文字转化为字节流用socket收发通讯,然后另一端具体的解析。或者用xml文档定义各个含义,然后收发解析。
import java.awt.*;class FormatText
{
private String formatText="";
private String nickName,fname,content;
private String[] resolveText;
private int fType,fSize,cR,cG,cB;
private Color fColor;
public FormatText(){}
//文字名称,文字类型,文字大小,文字颜色,正文
public void setFormatText(String nickName,String fName,int fType,int fSize,int cR,int cG,int cB,String content)
{
formatText=nickName+"╋"+fName+"╋"+fType+"╋"+fSize+"╋"+cR+"╋"+cG+"╋"+cB+"╋"+content;
resolveFormatText();
}
public String getNickName()
{
return nickName;
}
public String getFormatText()
{
return formatText;
}
public String getFontName()
{
return fname;
}
public int getFontType()
{
return fType;
}
public int getFontSize()
{
return fSize;
}
public Color getFontColor()
{
fColor=new Color(cR,cG,cB);
return fColor;
}
public String getTextContent()
{
return content;
}
public boolean getFontBold()
{
if(fType==1 || fType==3)
return true;
else
return false;
}
public boolean getFotnItalic()
{
if(fType==2 || fType==3)
return true;
else
return false;
}
private void resolveFormatText()
{
resolveText=Pattern.compile("╋").split(formatText,8);
nickName=resolveText[0];
fname=resolveText[1];
fType=Integer.parseInt(resolveText[2]);
fSize=Integer.parseInt(resolveText[3]);
cR=Integer.parseInt(resolveText[4]);
cG=Integer.parseInt(resolveText[5]);
cB=Integer.parseInt(resolveText[6]);
content=resolveText[7];
}
}