写文件

    1. //
    2. // Source code recreated from a .class file by IntelliJ IDEA
    3. // (powered by FernFlower decompiler)
    4. //
    5. package ciscn.fina1.ezj4va;
    6. import java.io.BufferedReader;
    7. import java.io.File;
    8. import java.io.FileNotFoundException;
    9. import java.io.FileReader;
    10. import java.io.IOException;
    11. import java.io.Serializable;
    12. import javax.servlet.http.HttpServletRequest;
    13. import javax.servlet.http.HttpServletResponse;
    14. public class test implements Serializable {
    15. public test() {
    16. }
    17. private static String readFileToString(String filepath) throws FileNotFoundException, IOException {
    18. StringBuilder sb = new StringBuilder();
    19. String s = "";
    20. BufferedReader br = new BufferedReader(new FileReader(filepath));
    21. while((s = br.readLine()) != null) {
    22. sb.append(s + "\n");
    23. }
    24. br.close();
    25. String str = sb.toString();
    26. return str;
    27. }
    28. public void e(Object request, Object response) throws IOException, ClassNotFoundException {
    29. HttpServletResponse res = (HttpServletResponse)response;
    30. HttpServletRequest req = (HttpServletRequest)request;
    31. res.getWriter().write("hahah123");
    32. String[] filenames = (new File("C:/")).list();
    33. for(int i = 0; i < filenames.length; ++i) {
    34. res.getWriter().write(filenames[i] + "\n");
    35. }
    36. }
    37. public static void main(String[] args) throws Exception {
    38. readFileToString("C:\\Users\\Yang_99\\Desktop\\RCTFV\\ROOT\\exp.py");
    39. }
    40. }