FileInputStream fin;
FileOutputStream fout;
try{
try{
fin=new FileInputStream("E:\\ayy\\test2\\Hellojava.txt");//args[0];//这里的txt文件里英文字母后面跟有汉字的,
}catch(FileNotFoundException e){
System.out.println("Input File Not Found...");
return;
}
try{
fout=new FileOutputStream("E:\\ayy\\test2\\Hellojava_Copy.txt");//args[1];
}catch(FileNotFoundException e){
System.out.println("Output File Not Found...");
return;
}
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("Usage: CopyFile From To");
return;
}
try{
do{
i=fin.read();
if(i!=-1)fout.write(i);
System.out.print((char)i);//读取的时候txt文件中的汉字就变?了,该怎么处理
for(int t=10000000;t>0;t--){};//这里有让线程睡眠几秒的方法码?相当于sleep(1000)这种效果FileInputStream fin;
FileOutputStream fout;
try{
try{
fin=new FileInputStream("E:\\ayy\\test2\\Hellojava.txt");//args[0];
}catch(FileNotFoundException e){
System.out.println("Input File Not Found...");
return;
}
try{
fout=new FileOutputStream("E:\\ayy\\test2\\Hellojava_Copy.txt");//args[1];
}catch(FileNotFoundException e){
System.out.println("Output File Not Found...");
return;
}
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("Usage: CopyFile From To");
return;
}
try{
do{
i=fin.read();
if(i!=-1)fout.write(i);
System.out.print((char)i);
for(int t=10000000;t>0;t--){};
}while(i!=-1);
}catch(IOException e){
System.out.println("File Error...")
}while(i!=-1);
}catch(IOException e){
System.out.println("File Error...");
FileOutputStream fout;
try{
try{
fin=new FileInputStream("E:\\ayy\\test2\\Hellojava.txt");//args[0];//这里的txt文件里英文字母后面跟有汉字的,
}catch(FileNotFoundException e){
System.out.println("Input File Not Found...");
return;
}
try{
fout=new FileOutputStream("E:\\ayy\\test2\\Hellojava_Copy.txt");//args[1];
}catch(FileNotFoundException e){
System.out.println("Output File Not Found...");
return;
}
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("Usage: CopyFile From To");
return;
}
try{
do{
i=fin.read();
if(i!=-1)fout.write(i);
System.out.print((char)i);//读取的时候txt文件中的汉字就变?了,该怎么处理
for(int t=10000000;t>0;t--){};//这里有让线程睡眠几秒的方法码?相当于sleep(1000)这种效果FileInputStream fin;
FileOutputStream fout;
try{
try{
fin=new FileInputStream("E:\\ayy\\test2\\Hellojava.txt");//args[0];
}catch(FileNotFoundException e){
System.out.println("Input File Not Found...");
return;
}
try{
fout=new FileOutputStream("E:\\ayy\\test2\\Hellojava_Copy.txt");//args[1];
}catch(FileNotFoundException e){
System.out.println("Output File Not Found...");
return;
}
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("Usage: CopyFile From To");
return;
}
try{
do{
i=fin.read();
if(i!=-1)fout.write(i);
System.out.print((char)i);
for(int t=10000000;t>0;t--){};
}while(i!=-1);
}catch(IOException e){
System.out.println("File Error...")
}while(i!=-1);
}catch(IOException e){
System.out.println("File Error...");
解决方案 »
- 急,求一个问题
- [求助]如何在Java中显示Video
- applet在客户端如何找到装载自己的HTML的路径(脱机)
- 请教关于javax.sql.dataSource
- 关于java的真诚请教??????????????????????????????
- 新手再次提问,各位帮帮忙,这样下去分数要没了:(
- 内部类到底有什么用处?
- JAVA BEAN 和 EJB 有什么异同,SERVLET 和 JSP 有什么异同
- 关于io的问题
- 有scjp证书,大学英语四级,六级证书.希望在上海找一份JAVA程序员的工作,哪位老兄可以给介绍引见一下.拜托了!
- 类的对象实例可以声名成数组吗?希望高手门给我指点一下小第的困惑!
- 请教写文件得问题
for(int t=10000000;t>0;t--){};//这里有让线程睡眠几秒的方法码?相当于sleep(1000)这种效果Thread.sleep(1000);
{
BufferedReader br = new BufferedReader(new FileReader(fn));
String str = br.readLine();
while (str != null)
{
str += br.readLine();
} System.out.println(str);
}这样就可以读中文了.
我是想让它遇到字母的时候显示字母,遇到汉字的时候显示汉字,这样可以实现吗?
while (str != null)
{
str += br.readLine();
str= new String(str .getBytes("ISO-8859-1"),"GBK");//转换中文,加上这句
}
if(i!=-1)fout.write(i);
System.out.print((char)i);
if(i!=-1)fout.write(i);
System.out.print((char)i);
i返回的是读文件的长度,是int类型,用(char)i转换,当然是你不认识的字符了。
应修改为:
Byte[] b = new Byte[1024];
i=fin.read(b);
if(i!=-1)fout.write(i);
System.out.print(new String(b,0,i));
就可以了。
Thread.sleep(1000);可以让线程睡1秒钟。
BufferedReader br = new BufferedReader(
new InputStreamReader(
new FileInputStream("d:\\message.properties"),"gb2312"));
StringBuffer sb=new StringBuffer();
String tmp=br.readLine();
while (tmp!=null)
{
sb.append(tmp);
tmp=br.readLine();
}
br.close();
br=null;
System.out.println(""+sb.toString());
}catch (Exception ex)
{
ex.printStackTrace();
}
这里加了Byte[]怎么用呢
stream 是字节流。
会出现汉字乱麻。
* 入力ストリームをバッファリング
*/
BufferedInputStream inBuffer = new BufferedInputStream(is); DataInputStream dataInStream = new DataInputStream(inBuffer); String fileName = fileUp.getFileName();
String fileKind = (fileName.substring(fileName.indexOf(".") + 1))
.toLowerCase();
String str;
int row = 0;
csvDataBeanList.clear();
if (dataInStream.readLine() == null) {
inBuffer.close();
dataInStream.close();
fileUp.destroy();
ActionMessages messages = new ActionMessages();
ActionMessage msg = new ActionMessage("message.6260");
messages.add(ActionMessages.GLOBAL_MESSAGE, msg);
saveMessages(req, messages);
return;
}