⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.java

📁 抽奖程序
💻 JAVA
字号:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Test {
 public static final String ENTER = System.getProperty("line.separator");

 public static String readFileContent(String fullPath) {
  File f = new File(fullPath);
  if (f.isDirectory()) {
   return null;
  }
  StringBuffer sb = new StringBuffer();
  BufferedReader br = null;
  FileReader fr = null;
  String strLine = null;
  try {
   fr = new FileReader(fullPath);
   br = new BufferedReader(fr);
   while ((strLine = br.readLine()) != null) {
    sb.append(strLine + ENTER);
   }
   br.close();
   fr.close();
  } catch (IOException e) {
   e.printStackTrace();
  }
  System.out.println(sb.toString());
  return sb.toString();
 }

 public static String readFileContentByByte(String fullPath) {
  File f = new File(fullPath);
  if (f.isDirectory()) {
   return null;
  }
  byte[] byteContent = new byte[0];
  byte[] buffer = new byte[4096];
  int iBeRead = -1;
  FileInputStream fis = null;
  String content = null;
  try {
   fis = new FileInputStream(fullPath);
   while ((iBeRead = fis.read(buffer, 0, 4096)) != -1) {
    byteContent = arrayAppendArray(byteContent, buffer, 0, iBeRead);
   }
   fis.close();
   content = new String(byteContent, "utf-8");
  } catch (Exception e1) {
   e1.printStackTrace();
  }

  return content;
 }

 public static byte[] arrayAppendArray(byte[] arrayDes, byte[] arraySrc,
   int offset, int length) {
  byte[] array = new byte[arrayDes.length + length];

  for (int i = 0; i < arrayDes.length; i++) {
   array[i] = arrayDes[i];
  }
  for (int i = arrayDes.length; i < arrayDes.length + length; i++) {
   array[i] = arraySrc[offset++];
  }
  arrayDes = null;
  arraySrc = null;
  return array;
 }

 public static void writeToFile(String fileContent, String fullPath) {

  try {
//   fileContent = new String(fileContent.getBytes("UTF-8")).trim();
   FileWriter fw = new FileWriter(fullPath);
   BufferedWriter bw = new BufferedWriter(fw);
   bw.write(fileContent);
   bw.close();
  } catch (IOException e) {
   e.printStackTrace();
  }
 }


 public static void main(String args[])throws Exception{
  String src = "F:\\111.txt";
  /*String des = "C:/DESC_BANK_ADD.jsp";
  String desUTF_8 = "C:/UTF_8DESC_BANK_ADD.jsp";
  */
  
  String content = Test.readFileContent(src);
 // Test.writeToFile(content, des);
  
  /*String utf_8Content = new String(content.getBytes("gbk"),"utf-8");
  Test.writeToFile(utf_8Content, desUTF_8);
*/ 
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -