A. java 如何打開一個文件夾

給你一段文件操作的例子

package com.file.sample;

import java.io.*;

public class FileOperate {
public FileOperate() {
}

/**
* 新建目錄
*
* @param folderPath
* String 如 c:/fqf
* @return boolean
*/
public void newFolder(String folderPath) {
try {
String filePath = folderPath;
filePath = filePath.toString();
java.io.File myFilePath = new java.io.File(filePath);
if (!myFilePath.exists()) {
myFilePath.mkdir();
}
} catch (Exception e) {
System.out.println("新建目錄操作出錯");
e.printStackTrace();
}
}

/**
* 新建文件
*
* @param filePathAndName
* String 文件路徑及名稱 如c:/fqf.txt
* @param fileContent
* String 文件內容
* @return boolean
*/
public void newFile(String filePathAndName, String fileContent) {

try {
String filePath = filePathAndName;
filePath = filePath.toString();
File myFilePath = new File(filePath);
if (!myFilePath.exists()) {
myFilePath.createNewFile();
}
FileWriter resultFile = new FileWriter(myFilePath);
PrintWriter myFile = new PrintWriter(resultFile);
String strContent = fileContent;
myFile.println(strContent);
resultFile.close();

} catch (Exception e) {
System.out.println("新建目錄操作出錯");
e.printStackTrace();

}

}

/**
* 刪除文件
*
* @param filePathAndName
* String 文件路徑及名稱 如c:/fqf.txt
* @param fileContent
* String
* @return boolean
*/
public void delFile(String filePathAndName) {
try {
String filePath = filePathAndName;
filePath = filePath.toString();
java.io.File myDelFile = new java.io.File(filePath);
myDelFile.delete();

} catch (Exception e) {
System.out.println("刪除文件操作出錯");
e.printStackTrace();

}

}

/**
* 刪除文件夾
*
* @param filePathAndName
* String 文件夾路徑及名稱 如c:/fqf
* @param fileContent
* String
* @return boolean
*/
public void delFolder(String folderPath) {
try {
delAllFile(folderPath); // 刪除完裡面所有內容
String filePath = folderPath;
filePath = filePath.toString();
java.io.File myFilePath = new java.io.File(filePath);
myFilePath.delete(); // 刪除空文件夾

} catch (Exception e) {
System.out.println("刪除文件夾操作出錯");
e.printStackTrace();

}

}

/**
* 刪除文件夾裡面的所有文件
*
* @param path
* String 文件夾路徑 如 c:/fqf
*/
public void delAllFile(String path) {
File file = new File(path);
if (!file.exists()) {
return;
}
if (!file.isDirectory()) {
return;
}
String[] tempList = file.list();
File temp = null;
for (int i = 0; i < tempList.length; i++) {
if (path.endsWith(File.separator)) {
temp = new File(path + tempList[i]);
} else {
temp = new File(path + File.separator + tempList[i]);
}
if (temp.isFile()) {
temp.delete();
}
if (temp.isDirectory()) {
delAllFile(path + "/" + tempList[i]);// 先刪除文件夾裡面的文件
delFolder(path + "/" + tempList[i]);// 再刪除空文件夾
}
}
}

/**
* 復制單個文件
*
* @param oldPath
* String 原文件路徑 如:c:/fqf.txt
* @param newPath
* String 復制後路徑 如:f:/fqf.txt
* @return boolean
*/
public void File(String oldPath, String newPath) {
try {
int bytesum = 0;
int byteread = 0;
File oldfile = new File(oldPath);
if (oldfile.exists()) { // 文件存在時
InputStream inStream = new FileInputStream(oldPath); // 讀入原文件
FileOutputStream fs = new FileOutputStream(newPath);
byte[] buffer = new byte[1444];
int length;
while ((byteread = inStream.read(buffer)) != -1) {
bytesum += byteread; // 位元組數 文件大小
System.out.println(bytesum);
fs.write(buffer, 0, byteread);
}
inStream.close();
}
} catch (Exception e) {
System.out.println("復制單個文件操作出錯");
e.printStackTrace();

}

}

/**
* 復制整個文件夾內容
*
* @param oldPath
* String 原文件路徑 如:c:/fqf
* @param newPath
* String 復制後路徑 如:f:/fqf/ff
* @return boolean
*/
public void Folder(String oldPath, String newPath) {

try {
(new File(newPath)).mkdirs(); // 如果文件夾不存在 則建立新文件夾
File a = new File(oldPath);
String[] file = a.list();
File temp = null;
for (int i = 0; i < file.length; i++) {
if (oldPath.endsWith(File.separator)) {
temp = new File(oldPath + file[i]);
} else {
temp = new File(oldPath + File.separator + file[i]);
}

if (temp.isFile()) {
FileInputStream input = new FileInputStream(temp);
FileOutputStream output = new FileOutputStream(newPath
+ "/" + (temp.getName()).toString());
byte[] b = new byte[1024 * 5];
int len;
while ((len = input.read(b)) != -1) {
output.write(b, 0, len);
}
output.flush();
output.close();
input.close();
}
if (temp.isDirectory()) {// 如果是子文件夾
Folder(oldPath + "/" + file[i], newPath + "/" + file[i]);
}
}
} catch (Exception e) {
System.out.println("復制整個文件夾內容操作出錯");
e.printStackTrace();

}

}

/**
* 移動文件到指定目錄
*
* @param oldPath
* String 如:c:/fqf.txt
* @param newPath
* String 如:d:/fqf.txt
*/
public void moveFile(String oldPath, String newPath) {
File(oldPath, newPath);
delFile(oldPath);

}

/**
* 移動文件到指定目錄
*
* @param oldPath
* String 如:c:/fqf.txt
* @param newPath
* String 如:d:/fqf.txt
*/
public void moveFolder(String oldPath, String newPath) {
Folder(oldPath, newPath);
delFolder(oldPath);

}

public static void main(String[] args){
FileOperate filedemo=new FileOperate();
filedemo.delAllFile("d:/test");
}
}

B. 怎麼用Java實現打開文件(打開方法)

Process p = Runtime.getRuntime().exec("notepad");.

可以用java執行cmd命令的方式打開程序,比如上面是打開windows記事本的指令。如果你要打專開其他文件,那就把notepad改成屬對應的文件名或程序名

C. java代碼中打開文件

如果你只想實現,就像雙擊了電腦某個文件
讓系統用其它應用去打開這個文件的話
可以用這個:
java.awt.Desktop.getDesktop().open(file);

D. java怎樣打開

  1. 開始鍵+R打開運行,然後輸入CMD,然後輸入命令切換到你java的那個文件夾,如:cd d:java

E. 怎麼打開java文件

可以使用JRE
(Java
Runtime
Enviroment)打開:
STEP1:將jad.exe拷貝到JRE的bin目錄下,如\Java\jre1.5.0_06\bin
STEP2:配置好你系統的JAVA環境,也就是在PATH里添加你的JRE的路徑什麼的...(這個還不懂??上GOOGLE去所搜一下,大把大把的)
STEP3:打開命令行,將目錄切換到你想要破解的.class文件的目錄.例如:我想要破解一個名為example.class的文件,它在e:\workspaces\里,那我就輸入cd
e:\workspaces\讓後回車.開始"脫"啦!:
反編譯單個JAVA語言的CLASS文件,在命令行輸入:jad
example.class回車.
讓後在你當前目錄會生成一個Example.jad的文件!把它的後綴改為java就可以閱讀了!(你可以忽略.class後綴)
選項
-s<後綴>允許你更改輸出文件的後綴.
jad
-sjava
example.class
這條命令生成文件'example.java'.當你同時使用選項-o和-sjava時要小心了,因為Jad會意外的覆蓋掉你的源文件.jad使用JAVA的CLASS文件名作為默認的輸出文件名.舉個例子,如果CLASS文件'example.class'包含了JAVA的CLASS'test'那麼jad會優先生成'test.jad'.如果你想要指定一自己的輸出文件名,請使用重定向:
jad
-p
example.class
>myexm.java選項-d允許你指定輸出文件到另外一個文件夾,這個文件夾將默認創建在當前目錄.舉個例子:
jad
-o
-dtest
-sjava
*.class
(或者jad
-o
-d
test
-s
java
*.class,兩者是一樣的)
這條命令反編譯所有.class文件在當前目錄並且放置所有輸出文件在目錄'test'以.java為後綴名.如果你想反編譯整個java類樹,用如下命令:
jad
-o
-r
-sjava
-dsrc
tree/**/*.class
這條命令反編譯所有.class文件位於'tree'以及子目錄並且建立輸出文件在'src'目錄的相對子目錄中依照類的包名.舉個例子,如果文件'tree/a/b/c.class'包含類'c'來自包'a.b',那麼數車文件的名字是'src/a/b/c.java'.萬一你想要檢查輸出文件的精確度或者就是僅僅是好奇,這兒有個選項-a,它讓jad使用JAVA虛擬機位元組碼作為注釋添加在輸出文件中.jad支持內部類和匿名類,當jad把通配符搭配到輸入的文件名時,它自動的跳過匹配的內部類.在UNIX系統中jad跳過內部類如果有多於一個類在命令行中指定了.
JRE官方下載地址:
http://java.sun.com/javase/downloads/index.jsp

F. 怎樣用java打開指定文件

File file = new File("文件絕對路徑");
Desktop.getDesktop().open(file);
即可調用系統的默認打開工具,打開這個文件

G. 怎麼用java代碼打開txt文件

runtime.exec(...);
sample:
command-line
:
texteditor.exe
"\pub\help.txt"
意思是:通過命令行運行名為
texteditor.exe
程序,並在啟動這個程序時候通過命令行參數傳遞一個將要被打開的名為help.txt
的文件
途徑二:用
textarea
裝載文本內容顯示

H. 如何在Java中打開TXT文件

importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileNotFoundException;
importjava.io.IOException;

publicclassReadText{

publicstaticvoidmain(String[]args)
{
readTextContent();
}

()
{

try
{
Filefile=newFile("E://test.txt");
FileInputStreamfis=newFileInputStream(file);
Stringstr="";
byte[]bytes=newbyte[1024];
intlength=0;
while((length=fis.read(bytes))!=-1)
{
str+=newString(bytes,0,length);
}

System.out.println(str);

}catch(FileNotFoundExceptione)
{
e.printStackTrace();
}catch(IOExceptione)
{
e.printStackTrace();
}
}
}

I. 如何打開java文件

可以使用JRE (Java Runtime Enviroment)打開: STEP1:將jad.exe拷貝到JRE的bin目錄下,如\Java\jre1.5.0_06\bin STEP2:配置好你系統的JAVA環境,也就是在PATH里添加你的JRE的路徑什麼的...(這個還不懂??上GOOGLE去所搜一下,大把大把的) STEP3:打開命令行,將目錄切換到你想要破解的.class文件的目錄.例如:我想要破解一個名為example.class的文件,它在e:\workspaces\里,那我就輸入cd e:\workspaces\讓後回車.開始"脫"啦!: 反編譯單個JAVA語言的CLASS文件,在命令行輸入:jad example.class回車. 讓後在你當前目錄會生成一個Example.jad的文件!把它的後綴改為java就可以閱讀了!(你可以忽略.class後綴) 選項 -s<後綴>允許你更改輸出文件的後綴. jad -sjava example.class 這條命令生成文件'example.java'.當你同時使用選項-o和-sjava時要小心了,因為Jad會意外的覆蓋掉你的源文件.jad使用JAVA的CLASS文件名作為默認的輸出文件名.舉個例子,如果CLASS文件'example.class'包含了JAVA的CLASS'test'那麼jad會優先生成'test.jad'.如果你想要指定一自己的輸出文件名,請使用重定向: jad -p example.class >myexm.java選項-d允許你指定輸出文件到另外一個文件夾,這個文件夾將默認創建在當前目錄.舉個例子: jad -o -dtest -sjava *.class (或者jad -o -d test -s java *.class,兩者是一樣的) 這條命令反編譯所有.class文件在當前目錄並且放置所有輸出文件在目錄'test'以.java為後綴名.如果你想反編譯整個java類樹,用如下命令: jad -o -r -sjava -dsrc tree/**/*.class 這條命令反編譯所有.class文件位於'tree'以及子目錄並且建立輸出文件在'src'目錄的相對子目錄中依照類的包名.舉個例子,如果文件'tree/a/b/c.class'包含類'c'來自包'a.b',那麼數車文件的名字是'src/a/b/c.java'.萬一你想要檢查輸出文件的精確度或者就是僅僅是好奇,這兒有個選項-a,它讓jad使用JAVA虛擬機位元組碼作為注釋添加在輸出文件中.jad支持內部類和匿名類,當jad把通配符搭配到輸入的文件名時,它自動的跳過匹配的內部類.在UNIX系統中jad跳過內部類如果有多於一個類在命令行中指定了. JRE官方下載地址: http://java.sun.com/javase/downloads/index.jsp

J. java 怎麼打開文件

如果我們要讀取HelloWorld.class的文件:
首先構造數據輸入流對象:
FileInputStream fis=new FileInputStream("HelloWorld.class");
DataInputStream dis=new DataInputStream(fis);
這里引入java.io.FileInputStream類和java.io.DataInputStream類
接下來就可以利用數據輸入流類的方法來讀取二進制文件的數據了:
dis.readInt()--讀出來是整形
dis.readByte()--讀出來是位元組類型
最後關閉輸入流。