.NET开发中经常用到的扩展方法
整理一下自己经常用到的几个扩展方法,在实际项目中确实好用,节省了不少的工作量。
1 匿名对象转化
在WinForm中,如果涉及较长时间的操作,我们一般会用一个BackgroundWorker来做封装长时间的操作,给它传递一个类型参数。
var parm = new { UserId = txtUserId.Text, UserText = txtText.Text, TabIndex = tabControl.SelectedIndex, CheckUrl = urls,
SupportFormat = supportFormat, DeleteMHT = chkDelete.Checked, FileFormat=supportFileFormat };
backgroundWorker.RunWorkerAsync(parm);
注意到一点,我这里没有用一个类型,而是用一个匿名类型,以节省类型的定义。这种场景经常遇到,比如这个后台方法需要传三个参数,那个后台方法需要五个参数,如果不用我这个方法,那你需要额外的定义二个类型,分别包含三个参数或是五个参数。
再来看DoWork时,如何使用这个匿名方法
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
#region Download
backgroundWorker.ReportProgress(10, string.Format("Analyst beginning......"));
var parm = e.Argument.TolerantCast(new { UserId = string.Empty, UserText = string.Empty, TabIndex = 0,
CheckUrl = new List<string>(), SupportFormat = string.Empty, DeleteMHT = false, FileFormat=string.Empty});
与RunWorkerAsnyc中传递的参数一样,定义一个匿名类型,各属性放默认值,然后调用TolerantCast方法,即可得到前面传入的值。
这个方法很大的方便了这种使用情景:方法与方法之间需要传递不固定的参数,但是又不愿意重新定义一个新的类型。这个方法不来自于CodeProject,我把它的代码转在下面,供您参考
/// <summary>
/// 转换匿名类型
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="o"></param>
/// <param name="example"></param>
/// <returns></returns>
public static T TolerantCast<T>(this object o, T example)
where T : class
{
IComparer<string> comparer = StringComparer.CurrentCultureIgnoreCase;
//Get constructor with lowest number of parameters and its parameters
var constructor = typeof (T).GetConstructors(
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance
).OrderBy(c => c.GetParameters().Length).First();
var parameters = constructor.GetParameters(); //Get properties of input object
var sourceProperties = new List<PropertyInfo>(o.GetType().GetProperties()); if (parameters.Length > 0)
{
var values = new object[parameters.Length];
for (int i = 0; i < values.Length; i++)
{
Type t = parameters[i].ParameterType;
//See if the current parameter is found as a property in the input object
var source = sourceProperties.Find(delegate(PropertyInfo item)
{
return comparer.Compare(item.Name, parameters[i].Name) == 0;
}); //See if the property is found, is readable, and is not indexed
if (source != null && source.CanRead &&
source.GetIndexParameters().Length == 0)
{
//See if the types match.
if (source.PropertyType == t)
{
//Get the value from the property in the input object and save it for use
//in the constructor call.
values[i] = source.GetValue(o, null);
continue;
}
else
{
//See if the property value from the input object can be converted to
//the parameter type
try
{
values[i] = Convert.ChangeType(source.GetValue(o, null), t);
continue;
}
catch
{
//Impossible. Forget it then.
}
}
}
//If something went wrong (i.e. property not found, or property isn't
//converted/copied), get a default value.
values[i] = t.IsValueType ? Activator.CreateInstance(t) : null;
}
//Call the constructor with the collected values and return it.
return (T) constructor.Invoke(values);
}
//Call the constructor without parameters and return the it.
return (T) constructor.Invoke(null);
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
2 集合对象上的扩展方法
先看例子,下面的测试方法
var @enum = new[] {1, 2, 3, 4}.AsEnumerable();
var sum = 0;
@enum.ForEach(n => sum += n);
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
这个扩展方法,可以直接在一个集合上执行一个Lambda表达式,返回结果,相当于有二个参数的Fun<T,T>,来看它的源代码定义
public static void ForEach<T>(this IEnumerable<T> @enum, Action<T> mapFunction)
{
foreach (var item in @enum) mapFunction(item);
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
3 字符串类型上的扩展方法
这里可以做的扩展方法比较多,一个明显的例子就是,依据String类型写的Helper类型方法最多。
来看一个字符串拼凑的例子,平时我们用string.Format这样的写法,如果用下面的扩展方法,看起来更直观一些。
string s = "{0} ought to be enough for {1}.";
string param0 = "64K";
string param1 = "everybody"; string expected = "64K ought to be enough for everybody.";
Assert.AreEqual(expected, s.FormatWith(param0, param1),
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
这个扩展方法的定义也简单,只有一行代码
/// <summary>
/// Formats a string with two literal placeholders.
/// </summary>
/// <param name="text">The extension text</param>
/// <param name="arg0">Argument 0</param>
/// <param name="arg1">Argument 1</param>
/// <returns>The formatted string</returns>
public static string FormatWith(this string text, object arg0, object arg1)
{
return string.Format(text, arg0, arg1);
}
可以考虑把参数延长到任意个,改写这个扩展方法,也只需要一行代码皆可
/// <summary>
/// Formats a string with two literal placeholders.
/// </summary>
/// <param name="text">The extension text</param>
/// <param name="arg0">Argument 0</param>
/// <param name="arg1">Argument 1</param>
/// <returns>The formatted string</returns>
public static string FormatWith(this string text, params object[] args))
{
return string.Format(text, args);
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
另一个有用的扩展方法是字符串与枚举类型之间的转化,扩展方法定义如下
/// <summary>
/// Parses a string into an Enum
/// </summary>
/// <typeparam name="T">The type of the Enum</typeparam>
/// <param name="value">String value to parse</param>
/// <returns>The Enum corresponding to the stringExtensions</returns>
public static T ToEnum<T>(this string value)
{
return ToEnum<T>(value, false);
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
参考下面的例子,使用这个实用的扩展方法
enum ProductVersion
{
Standard,
Enteprise,
Ultimate
} [TestMethod]
public void StringToEnumTest()
{
Assert.AreEqual(ProductVersion.Standard, "Standard".ToEnum<ProductVersion>());
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
4 数字类型上的扩展方法
我这里有一个明显的例子是显示容量的扩展方法,请看下面的方法组:
/// <summary>
/// Kilobytes
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static int KB(this int value)
{
return value * 1024;
} /// <summary>
/// Megabytes
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static int MB(this int value)
{
return value.KB() * 1024;
} /// <summary>
/// Gigabytes
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static int GB(this int value)
{
return value.MB() * 1024;
} /// <summary>
/// Terabytes
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static long TB(this int value)
{
return (long)value.GB() * (long)1024;
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
用起来就很轻松了,简单的一行代码,获取容量的数字值
var kb = 1.KB();
var mb = 1.MB();
var gb = 1.GB();
var tb = 1.TB();
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
最后一组扩展方法在计算百分比中经常遇到,比如统计计算,任务完成百分比计算:
#region PercentageOf calculations /// <summary>
/// The numbers percentage
/// </summary>
/// <param name="number">The number.</param>
/// <param name="percent">The percent.</param>
/// <returns>The result</returns>
public static decimal PercentageOf(this int number, int percent)
{
return (decimal)(number * percent / 100);
} /// <summary>
/// Percentage of the number.
/// </summary>
/// <param name="percent">The percent</param>
/// <param name="number">The Number</param>
/// <returns>The result</returns>
public static decimal PercentOf(this int position, int total)
{
decimal result = 0;
if (position > 0 && total > 0)
result = (decimal)position / (decimal)total * 100;
return result;
}
public static decimal PercentOf(this int? position, int total)
{
if (position == null) return 0; decimal result = 0;
if (position > 0 && total > 0)
result = (decimal)((decimal)position / (decimal)total * 100);
return result;
} /// <summary>
/// The numbers percentage
/// </summary>
/// <param name="number">The number.</param>
/// <param name="percent">The percent.</param>
/// <returns>The result</returns>
public static decimal PercentageOf(this int number, float percent)
{
return (decimal)(number * percent / 100);
} /// <summary>
/// Percentage of the number.
/// </summary>
/// <param name="percent">The percent</param>
/// <param name="number">The Number</param>
/// <returns>The result</returns>
public static decimal PercentOf(this int position, float total)
{
decimal result = 0;
if (position > 0 && total > 0)
result = (decimal)((decimal)position / (decimal)total * 100);
return result;
} /// <summary>
/// The numbers percentage
/// </summary>
/// <param name="number">The number.</param>
/// <param name="percent">The percent.</param>
/// <returns>The result</returns>
public static decimal PercentageOf(this int number, double percent)
{
return (decimal)(number * percent / 100);
} /// <summary>
/// Percentage of the number.
/// </summary>
/// <param name="percent">The percent</param>
/// <param name="number">The Number</param>
/// <returns>The result</returns>
public static decimal PercentOf(this int position, double total)
{
decimal result = 0;
if (position > 0 && total > 0)
result = (decimal)((decimal)position / (decimal)total * 100);
return result;
} /// <summary>
/// The numbers percentage
/// </summary>
/// <param name="number">The number.</param>
/// <param name="percent">The percent.</param>
/// <returns>The result</returns>
public static decimal PercentageOf(this int number, decimal percent)
{
return (decimal)(number * percent / 100);
} /// <summary>
/// Percentage of the number.
/// </summary>
/// <param name="percent">The percent</param>
/// <param name="number">The Number</param>
/// <returns>The result</returns>
public static decimal PercentOf(this int position, decimal total)
{
decimal result = 0;
if (position > 0 && total > 0)
result = (decimal)position / (decimal)total * 100;
return result;
} /// <summary>
/// The numbers percentage
/// </summary>
/// <param name="number">The number.</param>
/// <param name="percent">The percent.</param>
/// <returns>The result</returns>
public static decimal PercentageOf(this int number, long percent)
{
return (decimal)(number * percent / 100);
} /// <summary>
/// Percentage of the number.
/// </summary>
/// <param name="percent">The percent</param>
/// <param name="number">The Number</param>
/// <returns>The result</returns>
public static decimal PercentOf(this int position, long total)
{
decimal result = 0;
if (position > 0 && total > 0)
result = (decimal)position / (decimal)total * 100;
return result;
} #endregion
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
来看几个测试用例,增强对它的直观感受,因为涉及到的数值类型多一些,所以扩展方法的数量也多。
Assert.AreEqual(33.0M, 100.PercentageOf(33));
Assert.AreEqual(33.0M, 33.PercentOf(100));
Assert.AreEqual(33.0M, 100.PercentageOf((float)33.0F));
Assert.AreEqual(33.0M, 33.PercentOf((float)100.0F));
Assert.AreEqual(33.0M, 100.PercentageOf((double)33.0F));
Assert.AreEqual(33.0M, 33.PercentOf((double)100.0F));
Assert.AreEqual(33.0M, 100.PercentageOf((decimal)33.0M));
Assert.AreEqual(33.0M, 33.PercentOf((decimal)100.0M));
Assert.AreEqual(33.0M, 100.PercentageOf((long)33));
Assert.AreEqual(33.0M, 33.PercentOf((long)100));
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.NET开发中经常用到的扩展方法的更多相关文章
- java开发中遇到的问题及解决方法(持续更新)
摘自 http://blog.csdn.net/pony12/article/details/38456261 java开发中遇到的问题及解决方法(持续更新) 工作中,以C/C++开发为主,难免与其他 ...
- IOS开发中数据持久化的几种方法--NSUserDefaults
IOS开发中数据持久化的几种方法--NSUserDefaults IOS 开发中,经常会遇到需要把一些数据保存在本地的情况,那么这个时候我们有以下几种可以选择的方案: 一.使用NSUserDefaul ...
- Android应用开发中三种常见的图片压缩方法
Android应用开发中三种常见的图片压缩方法,分别是:质量压缩法.比例压缩法(根据路径获取图片并压缩)和比例压缩法(根据Bitmap图片压缩). 一.质量压缩法 private Bitmap com ...
- 浅谈Excel开发:九 Excel 开发中遇到的常见问题及解决方法
Excel开发过程中有时候会遇到各种奇怪的问题,下面就列出一些本人在开发中遇到的一些比较典型的问题,并给出了解决方法,希望对大家有所帮助. 一 插件调试不了以及错误导致崩溃的问题 在开发机器上,有时可 ...
- 关于html+ashx开发中几个问题的解决方法
在跟html+ashx打交道的园友们肯定会发现,这种模式虽然优美,但在开发中会遇到一些难处理的地方.我也不例外,下面是自己在实际开发中总结出来的几条经验,希望跟大家分享,更希望得到大家的建议和更好的解 ...
- 关于html+ashx开发中几个问题的解决方法 (转)
在跟html+ashx打交道的园友们肯定会发现,这种模式虽然优美,但在开发中会遇到一些难处理的地方.我也不例外,下面是自己在实际开发中总结出来的几条经验,希望跟大家分享,更希望得到大家的建议和更好的解 ...
- droid开发中监听器的三种实现方法(OnClickListener)
Android开发中监听器的实现有三种方法,对于初学者来说,能够很好地理解这三种方法,将能更好地增进自己对android中监听器的理解. 一.什么是监听器. 监听器是一个存在于View类下的接口,一般 ...
- phpcms模块开发中的小问题及解决方法
1.模块菜单中文名出错 在编写安装模块时候可能需要更改extention.inc.php中定义中文名称,由于反复安装或者通过phpcms的扩展->菜单管理 修改菜单名会导致中文名失败.解决办法很 ...
- Hive开发中使用变量的两种方法
在使用hive开发数据分析代码时,经常会遇到需要改变运行参数的情况,比如select语句中对日期字段值的设定,可能不同时间想要看不同日期的数据,这就需要能动态改变日期的值.如果开发量较大.参数多的话, ...
随机推荐
- Python:面向对象
面向过程:根据业务逻辑从上到下写垒代码 面向对象:对函数进行分类和封装 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 类:用来描述具有相同属性和方法的对象的集合,定义了该集合中 ...
- thymeleaf 中文乱码问题
使用thymeleaf后,即使使用org.springframework.web.filter.CharacterEncodingFilter也不能解决中文乱码问题了, 后来发现在org.thymel ...
- wkwebview 和 JS 自用
-(void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation{ ...
- zabbix监控超详细搭建过程
监控及zabbix 目录: 1 监控分类... 1 1.1 硬件监控... 1 1.2 系统监控... 2 1.3 网络监控... 3 1.4 ...
- Git常用命令(自己总是忘记,整理在这里)
1.git init 初始化一个空的git仓库 2.git clone +SSH地址 clone新的项目到本地 3.git add git add file 4.git commi ...
- 关于把A表中的数据复制到B表中(整理)
如果A,B两个表中没有重复数据且表结构一样可以直接 insert into B select * from A 如果结构不一样可以 insert into B(字段列表),select 字段列表 fr ...
- Java垃圾回收小结
一.如何确定某个对象是“垃圾”? 首先要搞清一个最基本的问题:如果确定某个对象是“垃圾”?既然垃圾收集器的任务是回收垃圾对象所占的空间供新的对象使用,那么垃圾收集器如何确定某个对象是“垃圾”?—即通过 ...
- ubuntu 14.04 键盘快捷键显示
安装完ubuntu14.04后 第一次登陆,会弹出键盘快捷键的一个大体预览, 也没有一个关闭按钮, 没看完就自动消失了. 让其重现的方法: 按住 super键 ,也就是键盘上的 win键 . 键盘 ...
- FileOutputStream保存文件
//保存文件,根据传入的路径,存放在SD卡目录下public boolean saveToPath(String title, String pageName) { Bitmap b = getCha ...
- 使用javamail发送邮件错误:550 5.7.1 Unable to relay
这两天由于客户的邮件服务器迁移,使用了NTLM的验证方式.系统使用javamailAPI进行发送邮件时,发现只能对内部邮箱进行发送,对外部邮箱进行发送的时候,报下图错误: 后面发现是由于系统的java ...