F:\sshc625\sshc625\JCreator Pro\MyProjects\Hello\Testingtemp.java:21: cannot resolve symbol
symbol : constructor BufferedReader (java.io.FileInputStream)
location: class java.io.BufferedReader
BufferedReader in=new BufferedReader(new FileInputStream(from));
symbol : constructor BufferedReader (java.io.FileInputStream)
location: class java.io.BufferedReader
BufferedReader in=new BufferedReader(new FileInputStream(from));
解决方案 »
- Win7 下软件安装无法创建桌面快捷式(自己开发打包的)
- 你对CVS了解有多少?
- ★★★请高手帮我分析一下,下面这段程序为什么会进入死循环?★★★
- 团结就是力量 我不认输 进者给分 免费放送经典的娱乐搞笑 各位兄弟姐妹 你们辛苦了 工作之余 记得休息哦
- java中如何自动回答使用Runtime.getRuntime().exec执行的外部程序的提问?
- j2sdk1.3.0的安装问题
- 100分给你,这个问题好难呀!!!如何让java执行一个应用程序!
- 怎样将Application改成Applet
- 有谁搞过vrml和java的联合应用,eai方式。
- JBUILDER中argv的调试问题
- 求发送接收XML 文件的例子?
- 一个javascript 问题
import java.io.*;public class Testingtemp
{
public static void main(String[] args)
throws FileNotFoundException
{
File a1=new File("a.txt");
File b1=new File("b.txt"); getTextFromHtml(a1,b1);
//System.out.println();
}
public static void getTextFromHtml(File f,File to)
{
File from=f;
File toText=to;
try
{
BufferedReader in=new BufferedReader(new FileReader(from));
String line=in.readLine();
PrintWriter outToText=
new PrintWriter(new FileOutputStream(toText));
if(line==null||line.trim().length()==0)
System.out.println("There is't any content!");
else
//converttxt(line);
outToText.print(line);
}
catch(FileNotFoundException e1)
{
e1.printStackTrace();
}
catch(IOException e2)
{
e2.printStackTrace();
}
}
public static String converttxt(String aContent)
{
String content=aContent;
content=content.replaceAll("[<]([^>]*)[>]","");
return content;
}
}
我试图将A中的内容写入B中,可是就是实现不了,希望大家指点。55555555555555555
public class Testingtemp
{
public static void copy(String from_name, String to_name)
throws IOException
{
File from_file = new File(from_name);
File to_file = new File(to_name);
if (!from_file.exists())
abort("没有这样的源文件: " + from_name);
if (!from_file.isFile())
abort("不能复制目录: " + from_name);
if (!from_file.canRead())
abort("源文件不是可读文件: " + from_name);
if (to_file.isDirectory())
to_file = new File(to_file, from_file.getName()); String parent = to_file.getParent();
if (parent == null)
parent = System.getProperty("user.dir");
File dir = new File(parent);
if (!dir.exists())
abort("目标目录不存在。 "+parent);
if (dir.isFile())
abort("指定的目标不是目录 " + parent);
if (!dir.canWrite())
abort("指定的目标目录不是可写的 " + parent);
FileInputStream from = null;
FileOutputStream to = null;
try {
from = new FileInputStream(from_file);
to = new FileOutputStream(to_file);
byte[] buffer = new byte[4096];
int bytes_read; while((bytes_read = from.read(buffer)) != -1)
to.write(buffer, 0, bytes_read);
}
finally {
if (from != null) try { from.close(); } catch (IOException e) { ; }
if (to != null) try { to.close(); } catch (IOException e) { ; }
}
}
private static void abort(String msg) throws IOException {
throw new IOException("文件复制: " + msg);
}
public static void main(String[] args) {
try { copy("a.txt", "b.txt"); }
catch (IOException e) { System.err.println(e.getMessage());}
}
}我给你写了一个,应该能满足你的需要,如果有什么问题,叫我一下,共同学习,[email protected]
{
FileInputStream from=new FileInputStream(f);
FileOutputStream toText=new FileOutputStream(to);
int i;
while(true){
i=from.read();
if(i==-1) break;
//if you wann to filter sth.
//converttxt(((char)i)+"");
toText.write((byte)i);
toText.flush();
}
from.close();from=null;
toText.close();toText=null;
}
BufferedReader in=new BufferedReader(new FileInputStream(from));
BufferedReader读的是字符流,而FileInputStream读的是字节流,前者不能直接封装后者。
应该这样写:
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(from)));
InputStreamReader实现字节流到字符流的转换
BufferedReader in=new BufferedReader(new FileInputStream(from));改为:
BufferedReader in=new BufferedReader(new InputStreamkReader(new FileInputStream(from)));