java打開文件
1. java打開某個文件
常規文件用文件流打開讀取:
class openfile
{
  public static void main(String args[])
  {
    int temp;//定義一個臨時整型變數,存儲流數據 
    FileInputStream fis=new FileInputStream("文件完整路徑");//文件輸入流參數為文件名
     FileOutputStream fos=new FileOutputStream(FileDescriptor.out);//輸出流參數為默認顯示器
  while((temp=fis.read())!=-1)
      fos.write(temp);
    fis.close();
   fos.close();//用完關閉流
  }
}
2. 如何打開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
3. java代碼中打開文件
如果你只想實現,就像雙擊了電腦某個文件
讓系統用其它應用去打開這個文件的話
可以用這個:
java.awt.Desktop.getDesktop().open(file);
4. java 如何打開文件夾(包括文件夾內的文件夾)!
文件太多,過濾了下後綴為.mp3的所有文件:
packagecn..file;
importjava.io.File;
/**
*
*@authorAdministrator
*
*/
publicclassRead{
publicstaticvoidmain(String[]args){
getFileName("D:");
}
publicstaticvoidgetFileName(Stringpath){
Filefile=newFile(path);
if(file.isDirectory()){
File[]dirFile=file.listFiles();
if(dirFile!=null){
for(Filef:dirFile){
if(f.isDirectory())
getFileName(f.getAbsolutePath());
else{
if(f.getAbsolutePath().endsWith(".mp3")){
System.out.println(f.getAbsolutePath());
}
}
}
}
}
}
}
列出所有文件將if (f.getAbsolutePath().endsWith(".mp3"))
刪除!
結果:
D:KwDownloadxSong劉珂矣-半壺紗.mp3
D:KwDownloadxSong劉珂矣-芙蓉雨.mp3
D:KwDownloadxSong墨明棋妙-蘭若詞 (墨明棋妙版).mp3
D:KwDownloadxSong孫子涵-唐人.mp3
D:KwDownloadxSong孫露-不甘寂寞 - 中四 2012新概念.mp3
D:KwDownloadxSong孫露-你是我今生最愛的女孩.mp3
D:KwDownloadxSong孫露-我的愛情被你燒成灰.mp3
D:KwDownloadxSong孫露-離別的秋天.mp3
D:KwDownloadxSong小5-離殤.mp3
D:KwDownloadxSong崔子格&徐譽滕-相思網.mp3
D:KwDownloadxSong影視原聲-殺破狼.mp3
D:KwDownloadxSong心然-千年緣(《仙劍奇俠傳四》游戲插曲).mp3
D:KwDownloadxSong董貞-白素貞.mp3
D:KwDownloadxSong藍心湄-一見鍾情.mp3
D:KwDownloadxTemp 5E1D065515DA6EE.mp3
D:.mp3
D:.mp3
D:.mp3
D:.mp3
D:.mp3
D:.mp3
D:.mp3
D:.mp3
D:.mp3
D:SoftWare編程軟體android-sdk_r21.1-windowsandroid-sdk-windowsandroid-4samplesApiDemos
es
aw	est_cbr.mp3
D:SoftWare編程軟體android-sdk_r21.1-windowsandroid-sdk-windowsplatformsandroid-4samplesApiDemos
es
aw	est_cbr.mp3
D:SoftWare編程軟體android-sdk_r21.1-windowsandroid-sdk-windowssamplesandroid-17ApiDemos
es
aw	est_cbr.mp3
5. 怎麼用Java實現打開文件(打開方法)
Process p = Runtime.getRuntime().exec("notepad");.
可以用java執行cmd命令的方式打開程序,比如上面是打開windows記事本的指令。如果你要打開其他文件,那就把notepad改成對應的文件名或程序名
6. 如何用eclipse打開並運行一個已經寫好的java文件
(1)新建一個項目
可以是java project也可以就用project

(6)java打開文件擴展閱讀
新建包操作注意新建類的名字要和代碼的公共類名稱相同,代碼中會自動聲明包(例:package text1)還可以在新建類下,刪掉之前設置的類,直接添加復制的java文件,不過要自己聲明包。
大多數用戶很樂於將 Eclipse 當作 Java 集成開發環境(IDE)來使用,但 Eclipse 的目標卻不僅限於此。
Eclipse 還包括插件開發環境(Plug-in Development Environment,PDE),這個組件主要針對希望擴展 Eclipse 的軟體開發人員,因為它允許他們構建與 Eclipse 環境無縫集成的工具。
由於 Eclipse 中的每樣東西都是插件,對於給 Eclipse 提供插件,以及給用戶提供一致和統一的集成開發環境而言,所有工具開發人員都具有同等的發揮場所。
參考資料:網路 eclipse
7. 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"); 
} 
}
8. 怎樣用java代碼實現打開指定的文件並顯示文件中的內容
import java.io.*;
 import java.awt.*;
 import java.awt.event.*;
 public class practice
 {  public static void main(String args[])
    {  int b;
       byte tom[]=new byte[25];
       try{  File f=new File("Example.java");
             FileInputStream in=new FileInputStream(f);
             while((b=in.read(tom,0,25))!=-1) 
                 {  String s=new String (tom,0,b);
                    System.out.print(s);
                 }
            in.close();
          }
       catch(IOException e)
          {  System.out.println("File read Error"+e);
          }
    }
 }
9. 怎樣用java打開指定文件
File file = new File("文件絕對路徑");
Desktop.getDesktop().open(file);
即可調用系統的默認打開工具,打開這個文件
10. Java中怎樣製作一個按鈕用以打開文件
if(obj==button1){
     JFileChooser chooser = new JFileChooser(); 
     int returnVal = chooser.showOpenDialog(frame); 
     if(returnVal == JFileChooser.APPROVE_OPTION) { 
  file = chooser.getSelectedFile();
     } 
 }
把這個放在事件處理的 actionPerform()方法中
button1就是你添加的按鈕 
這樣當你點擊button1的時候就會顯示文件選擇窗口
file就是你選擇的文件的File對象 你可以進行操作了
