包含java代码txt下载的词条
怎么用java代码打开txt文件?
import java.awt.*; import java.io.*; import java.awt.event.*; import javax.swing.*; public class Test { public Test() { JFrame f=new JFrame("TEST"); Container c=f.getContentPane(); c.setLayout(new FlowLayout()); JButton b=new JButton("帮助"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { String cmd="rundll32 url.dll FileProtocolHandler ";//启动相应的windows程序来打开文件 Process p = Runtime.getRuntime().exec(cmd); } catch (Exception e1) { System.out.println(e1); } } }); c.add(b); f.setBounds(100,100,300,300); f.setVisible(true); } public static void main(String arg[]) { new Test(); } } //Rundll32.exe DLLname,Functionname [Arguments] ,DLLname为需要执行的DLL文件名; //Functionname为前边需要执行的DLL文件的具体引出函数;[Arguments]为引出函数的具体参数
创新互联建站是一家专业提供濠江企业网站建设,专注与网站制作、成都做网站、HTML5建站、小程序制作等业务。10年已为濠江众多企业、政府机构等服务。创新互联专业网站制作公司优惠进行中。
java 关于创建txt文件并下载的实现方法
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
public class Io{
public static void main(String [] s){
File filename = new File("F:\\suncity.txt");
String filein="你好!";
RandomAccessFile mm = null;
try {
mm = new RandomAccessFile(filename,"rw");
mm.writeBytes(filein);
} catch (IOException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
} finally{
if(mm!=null){
try {
mm.close();
} catch (IOException e2) {
// TODO 自动生成 catch 块
e2.printStackTrace();
}
}
}
}
}
java代码怎样将oracle数据库中数据下载本地,为.txt文件或者.excel文件。
第一个类:
package totabel.action;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import topdf.TableToPdf;
import totabel.view.TabelData;
import totabel.xls.ExcelDemo;
public class TableAction implements ActionListener {
TabelData data;
public TableAction(TabelData data) {
this.data = data;
}
public void actionPerformed(ActionEvent e) {
String str = e.getActionCommand();
if ("添加".equals(str)) {
data.addData();
} else if ("导出到Excel".equals(str)) {
ExcelDemo demo = new ExcelDemo();
demo.method(data);
} else if ("删除".equals(str)) {
if (data.getRow() != -1) {
data.delRow();
} else {
JOptionPane.showMessageDialog(null, "请选择要删除的行!");
}
}else if("从Excel导入".equals(str)){
data.getXlsInfo();
}else if("从Excel导入到数据库".equals(str)){
data.toDb();
}else if("从table导出到pdf".equals(str)){
TableToPdf pdf=new TableToPdf();
pdf.newPage(data);
}else if("计算学分".equals(str)){
data.getXlsInfoToCredit();
}
}
}
第二个类:数据库连接
package totabel.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class JdbcConnection {
private static JdbcConnection con;
public static JdbcConnection getCon() {
if (con == null) {
con = new JdbcConnection();
}
return con;
}
public Connection getConnection() {
Connection connection=null;
try {
Class.forName("oracle.jdbc.OracleDriver");
String url = "jdbc:oracle:thin:@127.0.0.1:1521:oracle";
String user = "scott";
String password = "tiger";
connection = DriverManager.getConnection(url, user,
password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
// public static void main(String[] args) {
// JdbcConnection connection=new JdbcConnection();
// connection.getConnection("asd", "99");
// }
}
第三个类:主类(入口)
package totabel.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class JdbcConnection {
private static JdbcConnection con;
public static JdbcConnection getCon() {
if (con == null) {
con = new JdbcConnection();
}
return con;
}
public Connection getConnection() {
Connection connection=null;
try {
Class.forName("oracle.jdbc.OracleDriver");
String url = "jdbc:oracle:thin:@127.0.0.1:1521:oracle";
String user = "scott";
String password = "tiger";
connection = DriverManager.getConnection(url, user,
password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
// public static void main(String[] args) {
// JdbcConnection connection=new JdbcConnection();
// connection.getConnection("asd", "99");
// }
}
第四个类:
package totabel.xls;
import java.io.File;
import java.io.IOException;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;
import totabel.view.TabelData;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
public class ExcelDemo {
/**
*
* @param args
*/
private Vector title = new Vector();
private Vector[] array;
// public static void main(String[] args) {
// ExcelDemo demo = new ExcelDemo();
// demo.getXlsInfo();
//
// }
public void method(TabelData table) {
int row = table.getRowSize();
int column = table.getColumnSize();
WritableWorkbook book = null;
Vector title = table.setTitle();
Object[] str = title.toArray();
try {
book = Workbook.createWorkbook(new File("test.xls"));
WritableSheet sheet = book.createSheet("成绩表", 0);
for (int i = 0; i str.length; i++) {
sheet.addCell(new Label(i, 0, (String) str[i]));
}
for (int i = 1; i row + 1; i++) {
for (int j = 1; j column + 1; j++) {
sheet.addCell(new Label(j - 1, i, table.getTableInfo(i - 1,
j - 1)));
}
}
book.write();
JOptionPane.showMessageDialog(null, "导出完成!");
} catch (IOException e) {
e.printStackTrace();
} catch (RowsExceededException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
} finally {
try {
book.close();
} catch (WriteException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 输出Excel的数据到表单
*
* @return
*/
public Vector getXlsInfo() {
Vector v = new Vector();
jxl.Workbook rwb = null;
int index = 0;
try {
rwb = jxl.Workbook.getWorkbook(new File("test.xls"));
Sheet[] sheet = rwb.getSheets();
for (int i = 0; i sheet.length; i++) {
int rs = sheet[i].getRows();
array = new Vector[rs - 1];
for (int j = 1; j rs; j++) {
Cell[] cell = sheet[i].getRow(j);
Vector info = new Vector();
for (int k = 0; k cell.length; k++) {
info.add(cell[k].getContents());
}
array[index] = info;
index++;
v.add(info);
}
Cell[] titleCell = sheet[i].getRow(0);
for (int j = 0; j titleCell.length; j++) {
title.add(titleCell[j].getContents());
}
}
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
rwb.close();
}
return v;
}
public Vector getXlsInfoToCredit() {
Vector v = new Vector();
jxl.Workbook rwb = null;
try {
rwb = jxl.Workbook.getWorkbook(new File("d:/test/信科0821(南迁).xls"));
Sheet[] sheet = rwb.getSheets();
for (int i = 0; i sheet.length; i++) {
int rs = sheet[i].getRows();
array = new Vector[rs - 1];
for (int j = 1; j rs; j++) {
Cell[] cell = sheet[i].getRow(j);
Vector info = new Vector();
for (int k = 0; k cell.length; k++) {
// if(){
Pattern p = Pattern.compile("[0-9]{1,}");
Matcher m = p.matcher(cell[k].getContents());
if (m.matches()) {
int score = Integer.valueOf(cell[k].getContents());
float result = getScore(score);
info.add(result);
} else {
info.add(cell[k].getContents());
}
}
v.add(info);
}
Cell[] titleCell = sheet[i].getRow(0);
for (int j = 0; j titleCell.length; j++) {
title.add(titleCell[j].getContents());
}
}
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
rwb.close();
}
return v;
}
public float getScore(int n) {
float score = n;
if (n 60) {
score = 0;
return score;
} else {
if (n = 60 n = 63) {
score = (float) 1.0;
} else if (n = 64 n = 67) {
score = (float) 1.3;
} else if (n = 68 n = 71) {
score = (float) 1.7;
} else if (n = 72 n = 75) {
score = (float) 2.0;
} else if (n = 76 n = 79) {
score = (float) 2.3;
} else if (n = 80 n = 83) {
score = (float) 2.7;
} else if (n = 84 n = 87) {
score = (float) 3.0;
} else if (n = 88 n = 91) {
score = (float) 3.3;
} else if (n = 92 n = 95) {
score = (float) 3.7;
} else if (n = 96 n = 100) {
score = (float) 4.0;
}
return score;
}
}
public Vector getTitle() {
// getXlsInfo();
return title;
}
public Vector[] getArray() {
getXlsInfo();
return array;
}
}
因为时间问题就没有再写了,上面是我以前做的,不懂就q我
求java程序代码、要求输出一个txt文本、逐字输出、中间有sleep效果、谢谢拉~~~~~
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class 逐字输入 {
public static void main(String[] args) throws IOException, InterruptedException{
InputStreamReader in=new InputStreamReader(new FileInputStream("d:/1.txt"));
int b;
while((b=in.read())!=-1){
System.out.print((char)b);
Thread.sleep(100);
}
}
}
java /Web 工程 SSH中 数据下载到本地txt文件
可以通过“FileOutputStream”创建文件实例,之后过“OutputStreamWriter”流的形式进行存储,举例:
OutputStreamWriter pw = null;//定义一个流
pw = new OutputStreamWriter(new FileOutputStream(“D:/test.txt”),"GBK");//确认流的输出文件和编码格式,此过程创建了“test.txt”实例
pw.write("我是要写入到记事本文件的数据");//将要写入文件的内容,可以多次write
pw.close();//关闭流
备注:文件流用完之后必须及时通过close方法关闭,否则会一直处于打开状态,直至程序停止,增加系统负担。
文章标题:包含java代码txt下载的词条
URL链接:http://azwzsj.com/article/hcpjed.html