2016.04.22 / 17:37
ÅؽºÆ® ÆÄÀÏ »ý¼º ¹× ³»¿ë ¾÷µ¥ÀÌÆ®
Kiri
Ãßõ ¼ö 439
- // ÆÄÀÏ »ý¼º
- private void CreateFile(String FilePath)
- {
- try
- {
- System.out.println(FilePath);
- int nLast = FilePath.lastIndexOf("\\");
- String strDir = FilePath.substring(0, nLast);
- String strFile = FilePath.substring(nLast+1, FilePath.length());
- File dirFolder = new File(strDir);
- dirFolder.mkdirs();
- File f = new File(dirFolder, strFile);
- f.createNewFile();
- }
- catch (Exception ex)
- {
- System.out.println(ex.getMessage());
- }
- }
- // ÆÄÀÏ Å×½ºÆ® Àбâ
- private String ReadFileText(File file)
- {
- String strText = "";
- int nBuffer;
- try
- {
- BufferedReader buffRead = new BufferedReader(new FileReader(file));
- while ((nBuffer = buffRead.read()) != -1)
- {
- strText += (char)nBuffer;
- }
- buffRead.close();
- }
- catch (Exception ex)
- {
- System.out.println(ex.getMessage());
- }
- return strText;
- }
- // ÆÄÀÏ ¼öÁ¤
- private void UpdateFile(String FilePath, String Text)
- {
- try
- {
- File f = new File(FilePath);
- if (f.exists() == false)
- {
- // ÆÄÀÏÀÌ Á¸ÀçÇÏÁö ¾Ê´Â °æ¿ì ÆÄÀÏÀ» ¸¸µé¤¤´Ù.
- CreateFile(FilePath);
- }
- // ÆÄÀÏ Àбâ
- String fileText = ReadFileText(f);
- BufferedWriter buffWrite = new BufferedWriter(new FileWriter(f));
- Text = fileText + "\r\n" + Text;
- // ÆÄÀÏ ¾²±â
- buffWrite.write(Text, 0, Text.length());
- // ÆÄÀÏ ´Ý±â
- buffWrite.flush();
- buffWrite.close();
- }
- catch (Exception ex)
- {
- System.out.println(ex.getMessage());
- }
- }