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. cocos2d-x 3.0 alpha1 生成Qt qch帮助文档

    Qt的助手挺好用的. 比chm好多了 cocos2d-x使用doxygen生成文档. 默认生成的是html形式, 需要打开浏览器, 这个是比较耗资源吧 可以修改配置, 让doxygen同时输出qch形 ...

  2. UML 之 类图(Class Dragram)

    类图的基本目的是显示建模系统的类型,主要包括的类型有:类.接口.数据类型.组件等.UML为这些类型起了个名字叫分类器.通常可以把分类器当做类,但在技术上,分类器是更为普遍的术语.实例如下图: 1.类( ...

  3. SSH Spring3\Java1.8 “Unable to instantiate Action, xxAction, defined for 'xxAction_login' in namespace '/'null”

    1.Stacktraces Unable to instantiate Action,xxAction, defined for 'xxAction_login' in namespace '/'nu ...

  4. PHP读书笔记(7)- 函数

    自定义函数 PHP内置了超过1000个函数,因此函数使得PHP成为一门非常强大的语言.大多数时候我们使用系统的内置函数就可以满足需求,但是自定义函数通过将一组代码封装起来,使代码进行复用,程序结构与逻 ...

  5. iOS搜索框

    在iOS8以前搜索框是作为一个控件添加到TableViewController中, 有系统自带的搜索变量self.searchDisplayController 遵守一个搜索显示的协议<UISe ...

  6. struts配置信息

    struts.xml文件 <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PU ...

  7. 关于HTML的总结

    现在最新的Html版本是Html5,以前想在网页中做一个效果很费劲,但是现在Html5对标签都进行了封装,想做效果直接用标签就可以了. 以后百分之百是标签的时代.以后写java 就可以用标签.自定义标 ...

  8. 【推公式】UVa 10995 - Educational Journey

    1A~,但后来看人家的代码好像又写臭了,T^T... Problem A: Educational journey The University of Calgary team qualified f ...

  9. T-SQL使用JOIN执行UPDATE语句

    问题: In SQL Server, it's possible to insert into a table using a SELECT statement: INSERT INTO Table ...

  10. ActiveMQ(5.10.0) - Connection Configuration URI

    An Apache ActiveMQ connection can be configured by explicitly setting properties on the ActiveMQConn ...