1、编写日志

2、本地文件的读取和写入

3、Base64与图片的互相转换

Imports System.IO
Imports System.Text Public Class Cls_File #Region "编写日志" '根目录
Public Shared strCurrentPath As String 'Cls_File.WriteLog("FrmTask.Button1_Click", rtf.Text) Public Sub WriteLog(ByVal strModuelName As String, ByVal strDescription As String)
Try
'得到根目录
strCurrentPath = System.Windows.Forms.Application.StartupPath + "\AwLog\" Dim strDt As String = Date.Now.ToString("yyyy-MM-dd HH:mm:ss") '判断目录是否存在,存在
If Directory.Exists(strCurrentPath) = True Then
'得到文件目录
Dim strFilePath As String = strCurrentPath + DateTime.Today.ToString("yyyy-MM-dd", System.Globalization.DateTimeFormatInfo.InvariantInfo) + ".log" Dim sw As New StreamWriter(strFilePath, True)
sw.WriteLine(strDt + ":" + " " + strModuelName)
sw.WriteLine(strDescription)
sw.Close() Else
'根目录不存在
Dim dirPathInfo As DirectoryInfo = Directory.CreateDirectory(strCurrentPath)
dirPathInfo.Attributes = FileAttributes.Archive
'设置属性为存档 创建文件
Dim sw As New StreamWriter(strCurrentPath + DateTime.Today.ToString("yyyy-MM-dd") + ".log", True)
sw.WriteLine(strDt + ":" + " " + strModuelName)
sw.WriteLine(strDescription)
sw.Close()
End If Catch ex As Exception
MsgBox(ex.Message.ToString, MsgBoxStyle.Exclamation, "提示")
End Try End Sub #End Region #Region "本地文件读写字符串" Function ReadFile(ByVal FileName As String)
Dim MyReader = New StreamReader(FileName, Encoding.UTF8)
Dim MyText = MyReader.ReadToEnd()
MyReader.Close()
Return MyText
End Function Function WriteFile(ByVal FileName As String, ByVal strTmp As String)
Dim file As New System.IO.StreamWriter(FileName)
file.WriteLine(strTmp)
file.Close()
Return "ok"
End Function #End Region #Region "Base64与图片的互转" ''' <summary>
''' 将Base64转为图片
''' </summary>
''' <param name="base64"></param>
''' <returns></returns>
Public Shared Function Base64ToImage(ByVal base64 As String) As Image
Dim bases As String = base64
Dim bytes As Byte() = Convert.FromBase64String(bases)
Dim memStream As New MemoryStream(bytes)
Dim bit As New Bitmap(memStream)
Dim img As Image = bit
Return img
End Function ''' <summary>
''' 将图片转为Base64
''' </summary>
''' <param name="image"></param>
''' <returns></returns>
Public Shared Function ImageToBase64(ByVal Image As Image) As String
Try
Dim ms As New MemoryStream()
Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg) Dim arr As Byte() = New Byte(ms.Length - ) {} ms.Position =
ms.Read(arr, , CType(ms.Length, Integer))
ms.Close() Dim strbaser64 As [String] = Convert.ToBase64String(arr)
Return strbaser64
Catch ex As Exception
ImageToBase64 = ""
End Try
End Function #End Region

VB.Net 文件处理类的更多相关文章

  1. php 文件日志类

    php文件日志类,按年月日组织目录结构. <?php class FileLog { private $_filepath; //文件路径 private $_filename; //日志文件名 ...

  2. C++文件流类与文件流对象

    文件流是以外存文件为输入输出对象的数据流.输出文件流是从内存流向外存文件的数据,输入文件流是从外存文件流向内存的数据.每一个文件流都有一个内存缓冲区与之对应. 请区分文件流与文件的概念,不用误以为文件 ...

  3. 使用Java的多线程和IO流写一个文件复制功能类

    创建一个复制功能类,继承Thread类,重写run()方法,把FileInputStream和FileOutputStream输入输出流写在run()方法内.示例代码如下: import java.i ...

  4. Code片段 : .properties属性文件操作工具类 & JSON工具类

    摘要: 原创出处:www.bysocket.com 泥瓦匠BYSocket 希望转载,保留摘要,谢谢! “贵专” — 泥瓦匠 一.java.util.Properties API & 案例 j ...

  5. PHP文件处理类

    /** * 文件读写类 * 读取时,支持跳过N个/行字符然后再读取M个/行字符 * 支持每次读取时使用回调函数 * * 示例: * $file = new File('a.txt', 'r'); * ...

  6. 自动扫描FTP文件工具类 ScanFtp.java

    package com.util; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import ja ...

  7. 读取Config文件工具类 PropertiesConfig.java

    package com.util; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io ...

  8. C++学习47 文件的概念 文件流类与文件流对象 文件的打开与关闭

    迄今为止,我们讨论的输入输出是以系统指定的标准设备(输入设备为键盘,输出设备为显示器)为对象的.在实际应用中,常以磁盘文件作为对象.即从磁盘文件读取数据,将数据输出到磁盘文件.磁盘是计算机的外部存储器 ...

  9. C# - 文件操作类

    除了封装数据流的类 System.IO命名空间中还提供了可以操作文件和目录的类 Directory类 ns:System.IO Level:Object=>Directory 表示目录的类 用于 ...

随机推荐

  1. STM32W108芯片的SWD在IAR7.30版本中不能用

    提示说0x20000B8不能读,When Clear soft RAM BP

  2. Sql语句中的truncate,delete,drop的区别

    相同点: 1.truncate和不带where子句的delete.以及drop都会删除表内的数据. 不同点: 1. truncate 和 delete 只删除数据不删除表的结构(定义) drop 语句 ...

  3. QUI操作超时弹出登录窗口登录的处理方式

    在使用QUI开发的业务系统中,如果长时间没操作,session过期后,再次操作系统超时会自动跳转到登陆页面,如果当前有一些操作没有保存,需要重新登录后再次填写信息,用户体验很不好! 为了避免超时后页面 ...

  4. uva 784 Maze Exploration 染色 搜索水题 DFS

    染色问题,其实就是看看图上某一点能扩散多少. 用DFS解决,因为BFS不是很熟 =-=...以后要多练. 提交后32ms,优化了一下,在递归前进行判定,优化到22ms,不是优化的很好... 代码: # ...

  5. customerized convert from field type to DB field's type

    @LastModifiedDate @Convert(converter = LocalDateTime2TimestampConverter.class) @Slf4j public class L ...

  6. [转]oracle EBS 基础100问

    from:http://www.cnblogs.com/xiaoL/p/3593691.html  http://f.dataguru.cn/thread-51057-1-1.html 1001 OR ...

  7. 高效Count

    SQL Server快速查询某张表的当前行数   传统做法可能是select count(1) 但是往往会比较慢.推荐如下做法: SELECT ISNULL(MAX(rowcnt), 0) Curre ...

  8. Java中String类的format方法使用总结

    可参考: http://www.cnblogs.com/fsjohnhuang/p/4094777.html http://kgd1120.iteye.com/blog/1293633 String类 ...

  9. ActiveMQ(5.10.0) - Configuring the JAAS Authentication Plug-in

    JAAS provides pluggable authentication, which means ActiveMQ will use the same authentication API re ...

  10. asp网站发布步骤总结

    1.在VS2012中打开索要发布的网站,初始页可重命名为index.html或default.apx. 2.点击  生成>生成“网站”,然后“发布网站”. 3.进行发布设置: (1 配置文件 ( ...