2013-10-26 26 views

回答

-1

下面的行可能是你想要的。

public static String readFromFile(String filePath){ 
    String total=""; 
    File file=new File(filePath); 
     try { 
     String encoding="GBK"; 
       if(file.isFile() && file.exists()){ //判断文件是否存在 
       InputStreamReader read = new InputStreamReader(
         new FileInputStream(file),encoding);//考虑到汉子编码格式 
       BufferedReader bufferedReader = new BufferedReader(read); 
       String lineTxt = null; 
       while((lineTxt = bufferedReader.readLine()) != null){ 
        total+=lineTxt; 
       } 
       read.close(); 
     }else if(!file.exists()) 
     { 
     file.createNewFile(); 
     } 
     } catch (Exception e) { 
     System.out.println("读取文件内容出错"); 
     e.printStackTrace(); 
     } 
    return total; 
    } 
+0

如果你想读取系统文件,你可能会学习一些不良的linux,你可以通过使用这些代码来获得根存储:Process process = null; try {0} {0} {0} process = Runtime.getRuntime()。exec(“su”); process.waitFor(); (例外e){ } e.printStackTrace(); } finally { process.destroy(); } – orzangleli

相关问题