package fileRead;import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.xmlbeans.XmlException;public class ReadAndWrite {
//文件的复制
public static void main(String args[])
throws IOException, XmlException, OpenXML4JException{
File input = new File("E:/1.docx");
File output =new File("E:/2.docx");
FileInputStream in = new FileInputStream(input);
FileOutputStream out = new FileOutputStream(output);
int c;
while((c=in.read())!=-1){
out.write(c);
}
in.close();
out.close();
}
}
这段代码的功能是把一个文件的内容复制到另一个文件,现在我不希望全部复制,比如当我遇到#时就停止文件复制,因为我不知道文件何时会出现#,所以我不能使用read(byte[]b,int start,int length)函数;
顺便问一下:有没人做过把word2007文档内容批量导入数据库的,大家也可以说说思路
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.xmlbeans.XmlException;public class ReadAndWrite {
//文件的复制
public static void main(String args[])
throws IOException, XmlException, OpenXML4JException{
File input = new File("E:/1.docx");
File output =new File("E:/2.docx");
FileInputStream in = new FileInputStream(input);
FileOutputStream out = new FileOutputStream(output);
int c;
while((c=in.read())!=-1){
out.write(c);
}
in.close();
out.close();
}
}
这段代码的功能是把一个文件的内容复制到另一个文件,现在我不希望全部复制,比如当我遇到#时就停止文件复制,因为我不知道文件何时会出现#,所以我不能使用read(byte[]b,int start,int length)函数;
顺便问一下:有没人做过把word2007文档内容批量导入数据库的,大家也可以说说思路
解决方案 »
- 如何将String类型的数组传入另一个jsp页面中?
- 在javascript得到session后 在 dtree 遍历得节点的问题
- 上传限制大小,出提示框后,如何保留上传文件路径
- java高手请进!!!兄弟有个很难的问题!
- SOS......怎么删除数据库里重复的数据???
- 简单javabean封装Oracle表的问题,在线等
- String str; 和 String str = new String();有什么不同
- web start 传中文参数问题。
- Hibernate多对多,用户和角色的关系,求解~!
- org.apache.jasper.JasperException:这个C标签异常啊?没问题啊,好奇怪的问题
- 如何获取其余天数?
- JDK 1.6 + Tomcat 6.0 应该搭配 Eclipse 什么版本
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args) throws IOException{
File file=new File("E:/1.docx");
InputStreamReader read = new InputStreamReader (new FileInputStream(file),"UTF-8");
BufferedReader br=new BufferedReader(read);
FileWriter fw=new FileWriter("E:/2.docx");
String line=br.readLine();
while((line=br.readLine())!=null)
{
if(line.contains("#")){
line=line.substring(0,line.indexOf("#"));
fw.write(line);
break;
}else
fw.write(line);
}
br.close();
read.close();
fw.close();
}
}
line=line.substring(0,line.indexOf("#"));
fw.write(line);
break;
}else
fw.write(line);