??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲国产精品综合一区在线,在线看亚洲十八禁网站,精品亚洲成AV人在线观看http://m.tkk7.com/Vincent-chenxj/zh-cnMon, 12 May 2025 16:24:54 GMTMon, 12 May 2025 16:24:54 GMT60C# Sample code to talk to a printer using SNMP to get its status. http://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283093.htmlVincent-chenVincent-chenThu, 18 Jun 2009 09:24:00 GMThttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283093.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/283093.htmlhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283093.html#Feedback2http://m.tkk7.com/Vincent-chenxj/comments/commentRss/283093.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/283093.html

The following code will allow you to talk to a printer (running on a specific IP Address) to query its current status.

OLEPRNLib is a COM object that appears to be installed on XP and greater machines.

On my machine I made a reference on the COM tab of the Add Reference dialog to “oleprn 1.0 Type Library“ which lived in “c:\Windows\System32\oleprn.dll

using System;
using OLEPRNLib;
namespace PrinterStatus
{
/// 
 /// Summary description for Class1.
 /// 
 class Class1
{
/// 
  /// The main entry point for the application.
  /// 
  [STAThread]
static void Main(string[] args)
{
string[] ErrorMessageText = new string[8];
ErrorMessageText[0] = "service requested";
ErrorMessageText[1] = "offline";
ErrorMessageText[2] = "paper jammed";
ErrorMessageText[3] = "door open";
ErrorMessageText[4] = "no toner";
ErrorMessageText[5] = "toner low";
ErrorMessageText[6] = "out of paper";
ErrorMessageText[7] = "low paper";
int DeviceID = 1;
int Retries = 1;
int TimeoutInMS = 2000;
string CommunityString = "public";
string IPAddressOfPrinter = "10.3.0.93";
// Create instance of COM object
   OLEPRNLib.SNMP snmp = new OLEPRNLib.SNMP();
// Open the SNMP connect to the printer
   snmp.Open(IPAddressOfPrinter, CommunityString, Retries, TimeoutInMS);
// The actual Warning/Error bits
   uint WarningErrorBits = snmp.GetAsByte(String.Format("25.3.5.1.2.{0}", DeviceID));
// The actual Status
   uint StatusResult = snmp.GetAsByte(String.Format("25.3.2.1.5.{0}", DeviceID));
// uint Result2 = snmp.GetAsByte(String.Format("25.3.5.1.1.{0}", DeviceID));

string Result1Str = "";
switch (StatusResult)
{
case 2 : Result1Str = "OK";
break;
case 3 : Result1Str = "Warning: ";
break;
case 4 : Result1Str = "Being Tested: ";
break;
case 5 : Result1Str = "Unavailable for any use: ";
break;
default : Result1Str = "Unknown Status Code : "+StatusResult;
break;
}
string Str = "";
if ((StatusResult == 3 || StatusResult == 5))
{
int Mask = 1;
int NumMsg = 0;
for (int i=0; i< 8; i++)
{
if ((WarningErrorBits & Mask) == Mask)
{
if (Str.Length > 0)
Str += ", ";
Str += ErrorMessageText[i];
NumMsg = NumMsg + 1;
}
Mask = Mask * 2;
}
}
Console.WriteLine(Result1Str + Str);
}
}
}
posted on Monday, August 08, 2005 8:13 PM | Filed Under [ c# ]

Comments


# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
Hello.
I have been talked to a print by this code.
But I couldn't talk to Zebra Barcode Printer ( 140 Xi III Plus Model ).

I catched Ready Status and Out of Paper Error, but another status, for example, Printing(Running) and OffLine(Pause) status.

How can I know these status?
Posted by Park Jung Sup on 6/20/2007 4:25 PM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
Can you explain me what do "25.3.5.1.2.{0}" mean and what do "25.3.5.1.5.{0}"

is there any other code like this. if so can me provide the link so that i can know more about SNMP and try to handle/get status information the devices from remote location
Posted by theertendra on 8/29/2007 11:08 PM

# re: C# Sample code to talk to a printer using SNMP to get its status.


The codes that you see are called an OID and basically companies can obtain a private OID. see http://www.alvestrand.no/objectid/

There are common OID SNMP identifiers and the ones I was using in the article

The full OID for hrPrinterDetectedErrorState

.iso.org.dod.internet.mgmt.mib-2.host.hrDevice.hrPrinterTable.hrPrinterEntry.hrPrinterDetectedErrorState

or simply .1.3.6.1.2.1.25.3.5.1.2

This object represents any error conditions detected by the printer. The error conditions are encoded as bits in an octet string, with the following

definitions:
Condition Bit #
lowPaper 0
noPaper 1
lowToner 2
noToner 3
doorOpen 4
jammed 5
offline 6
serviceRequested 7
inputTrayMissing 8
outputTrayMissing 9
markerSupplyMissing 10
outputNearFull 11
outputFull 12
inputTrayEmpty 13
overduePreventMaint 14

Bits are numbered starting with the most significant bit of the first byte being bit 0, the least significant bit of the first byte being bit 7, the
most significant bit of the second byte being bit 8, and so on. A one bit encodes that the condition was detected, while a zero bit encodes that the condition was not detected.

This object is useful for alerting an operator to specific warning or error conditions that may occur, especially those requiring human intervention.

The best way to see what is around is to look at a MIB Browser
http://www.ireasoning.com/mibbrowser.shtml

If you download the tool above there is a free version and you would then load the Printer-MIB.MIB to get information like above.
Posted by Chris Crowe on 8/30/2007 4:44 AM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
My SNMP program is the simple program and write in the C# language. But I faced the problem that I need to type the IP address for my slave before I can get the MIB of my slave, how I can detect my slave's IP address directly without type the IP address? Can you give me some guidelines? Furthermore, I need some coding that write in C# that can show the status for my slaves, such as my slave is on or off. I hope that you can give me some guidelines. Thanks.
Posted by jelly on 1/12/2008 4:43 AM

# re: C# Sample code to talk to a printer using SNMP to get its status.


Hi All,

Can anybody can guide me how can i get all the printer names which are all attached in a Network ?
Posted by SEN on 5/2/2008 6:46 PM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
nice peace of code, thanks for sharing. unfortunately oleprn.dll isn't documented anywhere...but nevertheless i think i can use it for simple snmp queries.

seems to me as if you forgot to
snmp.close();
after querying.
Posted by andre on 7/3/2008 11:50 PM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
hi ,
I need to know whether the printer(dymo label printer) status active or not which was installed on the network (192.168.1.18\dymolabel shared) from the other machine.
the above example doesent work for me as i cant get the OID for the dymo label printer.
Can any one help me how to do the above requirement please
Posted by srinivas on 8/8/2008 2:47 AM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
after snmp.open at the following code
uint WarningErrorBits = snmp.GetAsByte(String.Format("25.3.5.1.2.{0}", DeviceID));

I am getting error "HRESULT E_FAIL has returned from a call to a COM component"
Can any one help me why I am getting the error!!

Posted by Ramesh on 9/4/2008 12:19 AM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
>> I am getting error "HRESULT E_FAIL has returned from a call to a COM component"

I just got this one too and when pinged it the printer was down.
Make sure the printer is up.
Posted by Victor on 10/2/2008 8:14 AM

# re: java Sample code to talk to a printer using SNMP to get its status.

Gravatar
i am going to develop simulator printer,so i need to develop printer mibs for virtual printer to operate them by snmp operation like set,get and trap by specifying oids.
Posted by vinay on 2/12/2009 3:01 AM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
hello everyone,
can anybody guide me to write the code in C# to access the of various node status in LAN using SNMP protocol.If any one is interested please mail me.
Posted by Sagar Mirajkar on 3/2/2009 3:15 AM

# re: C# Sample code to talk to a printer using SNMP to get its status.


hai thnks for giving this code to get status . I need more information about Printer like
1. whether Printer is Printing or not,
2. whether it is on Or off,
3.how many copies printed.

Can u help me
Posted by XXXXXXX on 3/17/2009 10:18 PM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
hello
Is it possible to use snmp on network to get informations (counter) from shared printers ?
Posted by jd on 3/17/2009 10:37 PM

# re: C# Sample code to talk to a printer using SNMP to get its status.


ya is it possible
Posted by XXXXXXX on 3/18/2009 12:20 AM

# re: C# Sample code to talk to a printer using SNMP to get its status.


can u reply quickly? i need to develop an appliacation controlling printer pls
Posted by XXXXXXX on 3/18/2009 12:40 AM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
you said it is possible to retrieve information from a shared printer (not à network printer) but how.

for a network printer i send an smtp request to the printer's IP with oid : 1.3.6.1.2.1.43.10.2.1.4.1.1

but for a shared printer i have to send it to the computer?
Posted by jd on 3/19/2009 3:55 AM


Vincent-chen 2009-06-18 17:24 发表评论
]]>
OIDhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283090.htmlVincent-chenVincent-chenThu, 18 Jun 2009 09:20:00 GMThttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283090.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/283090.htmlhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283090.html#Feedback0http://m.tkk7.com/Vincent-chenxj/comments/commentRss/283090.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/283090.html 服务器还包括盘利用率?br />


1、在windows上安装snmpQ控刉?>d/删除E序->d/删除windowslg->理和监视工?>详细信息->snmp协议
2、请你们先认真了(jin)解学?fn)PHP。在机器上安装APACHE+PHP+MYSQL的设计环境,q熟(zhn)环境。有问题随时联系我?br /> 3、你可以在本机安装snmp agent Q之后读取本机的相关参数?       

部分重要OID信息Q?br /> 1、内存大?br /> 服务器内存的OID是:(x).1.3.6.1.2.1.25.2.2.0Q不同的操作pȝ也是使用一L(fng)OID。但是网l设备内存的OIDҎ(gu)讑֤的生产厂商不同、型号不同,其OID也是不同的。Cisco的\由器和交换机都是.1.3.6.1.4.1.9.9.48.1.1.1.5.1。华Z换机Huawei 6502、Huawei 3526、Huawei 2403的OID?1.3.6.1.4.1.2011.6.1.2.1.1.2.0。而华三的H3C E328和H3C E126的OID?1.3.6.1.4.1.2011.6.1.2.1.1.2.65536?br /> 2?nbsp;       内存利用?br /> 与内存大的OID相对应,各被监控对象的内存利用率的OID如下Q?br /> 服务器内存利用率的OID?1.3.6.1.4.1.2021.4.6.0Q华Z换机的OID?1.3.6.1.4.1.2011.6.1.2.1.1.3.0。华三交换机的OID?1.3.6.1.4.1.2011.6.1.2.1.1.3.65536?br /> 3?nbsp;       盘大小?qing)利用?br /> 对于服务器的盘I间来说Q因为每个服务器的硬盘(sh)数和目录划分都不一P所以读取到的目录空间大对应的OID依次为:(x).1.3.6.1.2.1.25.2.3.1.5.1 ?1.3.6.1.2.1.25.2.3.1.5.2{,q且在读取每个目录空间大的同时要读取该目录的名UͼOID依次为:(x).1.3.6.1.2.1.25.2.3.1.3.1?1.3.6.1.2.1.25.2.3.1.3.2{)(j)作ؓ(f)该监控对象的描述。关于目录空间的利用率没有现成的OIDQ需要先获得目录I间的用量QOID依次为:(x).1.3.6.1.2.1.25.2.3.1.6.1?1.3.6.1.2.1.25.2.3.1.6.2、等Q,然后通过使用量与I间总量的比较得出利用率?br /> 4?nbsp;       端口状?br /> 对于服务器来_(d)有的服务器ؓ(f)?jin)完成复杂的功能需要配|多块网卡,因此也就?x)有多个端口需要监控。关于端口状态的OID则依ơؓ(f)Q?1.3.6.1.2.1.2.2.1.7.1?1.3.6.1.2.1.2.2.1.7.2?1.3.6.1.2.1.2.2.1.7.3{,除了(jin)端口状态系l还需要知道该端口的名UͼOID依次为:(x).1.3.6.1.2.1.2.2.1?.1?1.3.6.1.2.1.2.2.1.2.2?1.3.6.1.2.1.2.2.1.2.3{)(j)。在获取交换机的端口状态时首先只将状态UP的端口信息记录下来,再通过每个端口的作用来选择是否真的对其q行监控。一般网l管理员只需要监控那些用来与其它的网l设备互q的端口。这些端口的OID有的是连l的Q有的则是分散的Q但都属?1.3.6.1.2.1.2.2.1.7的分支?br />



CPU Statistics

Load
1 minute Load: .1.3.6.1.4.1.2021.10.1.3.1
5 minute Load: .1.3.6.1.4.1.2021.10.1.3.2
15 minute Load: .1.3.6.1.4.1.2021.10.1.3.3

CPU
percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0
raw user cpu time: .1.3.6.1.4.1.2021.11.50.0
percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0
raw system cpu time: .1.3.6.1.4.1.2021.11.52.0
percentages of idle CPU time: .1.3.6.1.4.1.2021.11.11.0
raw idle cpu time: .1.3.6.1.4.1.2021.11.53.0
raw nice cpu time: .1.3.6.1.4.1.2021.11.51.0

Memory Statistics

Total Swap Size: .1.3.6.1.4.1.2021.4.3.0
Available Swap Space: .1.3.6.1.4.1.2021.4.4.0
Total RAM in machine: .1.3.6.1.4.1.2021.4.5.0
Total RAM used: .1.3.6.1.4.1.2021.4.6.0
Total RAM Free: .1.3.6.1.4.1.2021.4.11.0
Total RAM Shared: .1.3.6.1.4.1.2021.4.13.0
Total RAM Buffered: .1.3.6.1.4.1.2021.4.14.0
Total Cached Memory: .1.3.6.1.4.1.2021.4.15.0

Disk Statistics

The snmpd.conf needs to be edited. Add the following (assuming a machine with a single / partition):

disk / 100000 (or)

includeAllDisks 10% for all partitions and disks

The OIDs are as follows

Path where the disk is mounted: .1.3.6.1.4.1.2021.9.1.2.1
Path of the device for the partition: .1.3.6.1.4.1.2021.9.1.3.1
Total size of the disk/partion (kBytes): .1.3.6.1.4.1.2021.9.1.6.1
Available space on the disk: .1.3.6.1.4.1.2021.9.1.7.1
Used space on the disk: .1.3.6.1.4.1.2021.9.1.8.1
Percentage of space used on disk: .1.3.6.1.4.1.2021.9.1.9.1
Percentage of inodes used on disk: .1.3.6.1.4.1.2021.9.1.10.1

Vincent-chen 2009-06-18 17:20 发表评论
]]>
OIDhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283089.htmlVincent-chenVincent-chenThu, 18 Jun 2009 09:20:00 GMThttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283089.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/283089.htmlhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283089.html#Feedback0http://m.tkk7.com/Vincent-chenxj/comments/commentRss/283089.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/283089.html 服务器还包括盘利用率?br />


1、在windows上安装snmpQ控刉?>d/删除E序->d/删除windowslg->理和监视工?>详细信息->snmp协议
2、请你们先认真了(jin)解学?fn)PHP。在机器上安装APACHE+PHP+MYSQL的设计环境,q熟(zhn)环境。有问题随时联系我?br /> 3、你可以在本机安装snmp agent Q之后读取本机的相关参数?       

部分重要OID信息Q?br /> 1、内存大?br /> 服务器内存的OID是:(x).1.3.6.1.2.1.25.2.2.0Q不同的操作pȝ也是使用一L(fng)OID。但是网l设备内存的OIDҎ(gu)讑֤的生产厂商不同、型号不同,其OID也是不同的。Cisco的\由器和交换机都是.1.3.6.1.4.1.9.9.48.1.1.1.5.1。华Z换机Huawei 6502、Huawei 3526、Huawei 2403的OID?1.3.6.1.4.1.2011.6.1.2.1.1.2.0。而华三的H3C E328和H3C E126的OID?1.3.6.1.4.1.2011.6.1.2.1.1.2.65536?br /> 2?nbsp;       内存利用?br /> 与内存大的OID相对应,各被监控对象的内存利用率的OID如下Q?br /> 服务器内存利用率的OID?1.3.6.1.4.1.2021.4.6.0Q华Z换机的OID?1.3.6.1.4.1.2011.6.1.2.1.1.3.0。华三交换机的OID?1.3.6.1.4.1.2011.6.1.2.1.1.3.65536?br /> 3?nbsp;       盘大小?qing)利用?br /> 对于服务器的盘I间来说Q因为每个服务器的硬盘(sh)数和目录划分都不一P所以读取到的目录空间大对应的OID依次为:(x).1.3.6.1.2.1.25.2.3.1.5.1 ?1.3.6.1.2.1.25.2.3.1.5.2{,q且在读取每个目录空间大的同时要读取该目录的名UͼOID依次为:(x).1.3.6.1.2.1.25.2.3.1.3.1?1.3.6.1.2.1.25.2.3.1.3.2{)(j)作ؓ(f)该监控对象的描述。关于目录空间的利用率没有现成的OIDQ需要先获得目录I间的用量QOID依次为:(x).1.3.6.1.2.1.25.2.3.1.6.1?1.3.6.1.2.1.25.2.3.1.6.2、等Q,然后通过使用量与I间总量的比较得出利用率?br /> 4?nbsp;       端口状?br /> 对于服务器来_(d)有的服务器ؓ(f)?jin)完成复杂的功能需要配|多块网卡,因此也就?x)有多个端口需要监控。关于端口状态的OID则依ơؓ(f)Q?1.3.6.1.2.1.2.2.1.7.1?1.3.6.1.2.1.2.2.1.7.2?1.3.6.1.2.1.2.2.1.7.3{,除了(jin)端口状态系l还需要知道该端口的名UͼOID依次为:(x).1.3.6.1.2.1.2.2.1?.1?1.3.6.1.2.1.2.2.1.2.2?1.3.6.1.2.1.2.2.1.2.3{)(j)。在获取交换机的端口状态时首先只将状态UP的端口信息记录下来,再通过每个端口的作用来选择是否真的对其q行监控。一般网l管理员只需要监控那些用来与其它的网l设备互q的端口。这些端口的OID有的是连l的Q有的则是分散的Q但都属?1.3.6.1.2.1.2.2.1.7的分支?br />



CPU Statistics

Load
1 minute Load: .1.3.6.1.4.1.2021.10.1.3.1
5 minute Load: .1.3.6.1.4.1.2021.10.1.3.2
15 minute Load: .1.3.6.1.4.1.2021.10.1.3.3

CPU
percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0
raw user cpu time: .1.3.6.1.4.1.2021.11.50.0
percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0
raw system cpu time: .1.3.6.1.4.1.2021.11.52.0
percentages of idle CPU time: .1.3.6.1.4.1.2021.11.11.0
raw idle cpu time: .1.3.6.1.4.1.2021.11.53.0
raw nice cpu time: .1.3.6.1.4.1.2021.11.51.0

Memory Statistics

Total Swap Size: .1.3.6.1.4.1.2021.4.3.0
Available Swap Space: .1.3.6.1.4.1.2021.4.4.0
Total RAM in machine: .1.3.6.1.4.1.2021.4.5.0
Total RAM used: .1.3.6.1.4.1.2021.4.6.0
Total RAM Free: .1.3.6.1.4.1.2021.4.11.0
Total RAM Shared: .1.3.6.1.4.1.2021.4.13.0
Total RAM Buffered: .1.3.6.1.4.1.2021.4.14.0
Total Cached Memory: .1.3.6.1.4.1.2021.4.15.0

Disk Statistics

The snmpd.conf needs to be edited. Add the following (assuming a machine with a single / partition):

disk / 100000 (or)

includeAllDisks 10% for all partitions and disks

The OIDs are as follows

Path where the disk is mounted: .1.3.6.1.4.1.2021.9.1.2.1
Path of the device for the partition: .1.3.6.1.4.1.2021.9.1.3.1
Total size of the disk/partion (kBytes): .1.3.6.1.4.1.2021.9.1.6.1
Available space on the disk: .1.3.6.1.4.1.2021.9.1.7.1
Used space on the disk: .1.3.6.1.4.1.2021.9.1.8.1
Percentage of space used on disk: .1.3.6.1.4.1.2021.9.1.9.1
Percentage of inodes used on disk: .1.3.6.1.4.1.2021.9.1.10.1

Vincent-chen 2009-06-18 17:20 发表评论
]]>
Cisco常用OIDhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283080.htmlVincent-chenVincent-chenThu, 18 Jun 2009 08:48:00 GMThttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283080.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/283080.htmlhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283080.html#Feedback0http://m.tkk7.com/Vincent-chenxj/comments/commentRss/283080.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/283080.html
pȝ状态相养I(x)
### THIS FILE WAS GENERATED BY MIB2SCHEMA
"org"		"1.3"
"dod"		"1.3.6"
"internet"		"1.3.6.1"
"directory"		"1.3.6.1.1"
"mgmt"		"1.3.6.1.2"
"experimental"		"1.3.6.1.3"
"private"		"1.3.6.1.4"
"enterprises"		"1.3.6.1.4.1"
"cisco"		"1.3.6.1.4.1.9"
"ciscoMgmt"		"1.3.6.1.4.1.9.9"
"ciscoEnvMonMIB"		"1.3.6.1.4.1.9.9.13"
"ciscoEnvMonObjects"		"1.3.6.1.4.1.9.9.13.1"
"ciscoEnvMonMIBNotificationEnables"		"1.3.6.1.4.1.9.9.13.2"
"ciscoEnvMonMIBNotificationPrefix"		"1.3.6.1.4.1.9.9.13.3"
"ciscoEnvMonMIBConformance"		"1.3.6.1.4.1.9.9.13.4"
"ciscoEnvMonPresent"		"1.3.6.1.4.1.9.9.13.1.1"
"ciscoEnvMonVoltageStatusTable"		"1.3.6.1.4.1.9.9.13.1.2"
"ciscoEnvMonTemperatureStatusTable"		"1.3.6.1.4.1.9.9.13.1.3"
"ciscoEnvMonFanStatusTable"		"1.3.6.1.4.1.9.9.13.1.4"
"ciscoEnvMonSupplyStatusTable"		"1.3.6.1.4.1.9.9.13.1.5"
"ciscoEnvMonAlarmContacts"		"1.3.6.1.4.1.9.9.13.1.6"
"ciscoEnvMonVoltageStatusEntry"		"1.3.6.1.4.1.9.9.13.1.2.1"
"ciscoEnvMonVoltageStatusIndex"		"1.3.6.1.4.1.9.9.13.1.2.1.1"
"ciscoEnvMonVoltageStatusDescr"		"1.3.6.1.4.1.9.9.13.1.2.1.2"
"ciscoEnvMonVoltageStatusValue"		"1.3.6.1.4.1.9.9.13.1.2.1.3"
"ciscoEnvMonVoltageThresholdLow"		"1.3.6.1.4.1.9.9.13.1.2.1.4"
"ciscoEnvMonVoltageThresholdHigh"		"1.3.6.1.4.1.9.9.13.1.2.1.5"
"ciscoEnvMonVoltageLastShutdown"		"1.3.6.1.4.1.9.9.13.1.2.1.6"
"ciscoEnvMonVoltageState"		"1.3.6.1.4.1.9.9.13.1.2.1.7"
"ciscoEnvMonTemperatureStatusEntry"		"1.3.6.1.4.1.9.9.13.1.3.1"
"ciscoEnvMonTemperatureStatusIndex"		"1.3.6.1.4.1.9.9.13.1.3.1.1"
"ciscoEnvMonTemperatureStatusDescr"		"1.3.6.1.4.1.9.9.13.1.3.1.2"
"ciscoEnvMonTemperatureStatusValue"		"1.3.6.1.4.1.9.9.13.1.3.1.3"
"ciscoEnvMonTemperatureThreshold"		"1.3.6.1.4.1.9.9.13.1.3.1.4"
"ciscoEnvMonTemperatureLastShutdown"		"1.3.6.1.4.1.9.9.13.1.3.1.5"
"ciscoEnvMonTemperatureState"		"1.3.6.1.4.1.9.9.13.1.3.1.6"
"ciscoEnvMonFanStatusEntry"		"1.3.6.1.4.1.9.9.13.1.4.1"
"ciscoEnvMonFanStatusIndex"		"1.3.6.1.4.1.9.9.13.1.4.1.1"
"ciscoEnvMonFanStatusDescr"		"1.3.6.1.4.1.9.9.13.1.4.1.2"
"ciscoEnvMonFanState"		"1.3.6.1.4.1.9.9.13.1.4.1.3"
"ciscoEnvMonSupplyStatusEntry"		"1.3.6.1.4.1.9.9.13.1.5.1"
"ciscoEnvMonSupplyStatusIndex"		"1.3.6.1.4.1.9.9.13.1.5.1.1"
"ciscoEnvMonSupplyStatusDescr"		"1.3.6.1.4.1.9.9.13.1.5.1.2"
"ciscoEnvMonSupplyState"		"1.3.6.1.4.1.9.9.13.1.5.1.3"
"ciscoEnvMonSupplySource"		"1.3.6.1.4.1.9.9.13.1.5.1.4"
"ciscoEnvMonEnableShutdownNotification"		"1.3.6.1.4.1.9.9.13.2.1"
"ciscoEnvMonEnableVoltageNotification"		"1.3.6.1.4.1.9.9.13.2.2"
"ciscoEnvMonEnableTemperatureNotification"		"1.3.6.1.4.1.9.9.13.2.3"
"ciscoEnvMonEnableFanNotification"		"1.3.6.1.4.1.9.9.13.2.4"
"ciscoEnvMonEnableRedundantSupplyNotification"		"1.3.6.1.4.1.9.9.13.2.5"
"ciscoEnvMonEnableStatChangeNotif"		"1.3.6.1.4.1.9.9.13.2.6"
"ciscoEnvMonMIBNotifications"		"1.3.6.1.4.1.9.9.13.3"
"ciscoEnvMonMIBCompliances"		"1.3.6.1.4.1.9.9.13.4.1"
"ciscoEnvMonMIBGroups"		"1.3.6.1.4.1.9.9.13.4.2"
"ciscoEnvMonMIBCompliance"		"1.3.6.1.4.1.9.9.13.4.1.1"
"ciscoEnvMonMIBComplianceRev1"		"1.3.6.1.4.1.9.9.13.4.1.2"
"ciscoEnvMonMIBGroup"		"1.3.6.1.4.1.9.9.13.4.2.1"
"ciscoEnvMonMIBGroupRev"		"1.3.6.1.4.1.9.9.13.4.2.2"
"ciscoEnvMonEnableStatChangeGroup"		"1.3.6.1.4.1.9.9.13.4.2.3"
"ciscoEnvMonMIBNotifGroup"		"1.3.6.1.4.1.9.9.13.4.2.4"
"ciscoEnvMonStatChangeNotifGroup"		"1.3.6.1.4.1.9.9.13.4.2.5"
"ciscoEnvMonMIBMiscNotifGroup"		"1.3.6.1.4.1.9.9.13.4.2.6"
pȝ内存?sh)息Q?/pre>
### THIS FILE WAS GENERATED BY MIB2SCHEMA
"org"		"1.3"
"dod"		"1.3.6"
"internet"		"1.3.6.1"
"directory"		"1.3.6.1.1"
"mgmt"		"1.3.6.1.2"
"experimental"		"1.3.6.1.3"
"private"		"1.3.6.1.4"
"enterprises"		"1.3.6.1.4.1"
"cisco"		"1.3.6.1.4.1.9"
"ciscoMgmt"		"1.3.6.1.4.1.9.9"
"ciscoMemoryPoolMIB"		"1.3.6.1.4.1.9.9.48"
"ciscoMemoryPoolObjects"		"1.3.6.1.4.1.9.9.48.1"
"ciscoMemoryPoolNotifications"		"1.3.6.1.4.1.9.9.48.2"
"ciscoMemoryPoolConformance"		"1.3.6.1.4.1.9.9.48.3"
"ciscoMemoryPoolTable"		"1.3.6.1.4.1.9.9.48.1.1"
"ciscoMemoryPoolUtilizationTable"		"1.3.6.1.4.1.9.9.48.1.2"
"ciscoMemoryPoolEntry"		"1.3.6.1.4.1.9.9.48.1.1.1"
"ciscoMemoryPoolType"		"1.3.6.1.4.1.9.9.48.1.1.1.1"
"ciscoMemoryPoolName"		"1.3.6.1.4.1.9.9.48.1.1.1.2"
"ciscoMemoryPoolAlternate"		"1.3.6.1.4.1.9.9.48.1.1.1.3"
"ciscoMemoryPoolValid"		"1.3.6.1.4.1.9.9.48.1.1.1.4"
"ciscoMemoryPoolUsed"		"1.3.6.1.4.1.9.9.48.1.1.1.5"
"ciscoMemoryPoolFree"		"1.3.6.1.4.1.9.9.48.1.1.1.6"
"ciscoMemoryPoolLargestFree"		"1.3.6.1.4.1.9.9.48.1.1.1.7"
"ciscoMemoryPoolUtilizationEntry"		"1.3.6.1.4.1.9.9.48.1.2.1"
"ciscoMemoryPoolUtilization1Min"		"1.3.6.1.4.1.9.9.48.1.2.1.1"
"ciscoMemoryPoolUtilization5Min"		"1.3.6.1.4.1.9.9.48.1.2.1.2"
"ciscoMemoryPoolUtilization10Min"		"1.3.6.1.4.1.9.9.48.1.2.1.3"
"ciscoMemoryPoolCompliances"		"1.3.6.1.4.1.9.9.48.3.1"
"ciscoMemoryPoolGroups"		"1.3.6.1.4.1.9.9.48.3.2"
"ciscoMemoryPoolCompliance"		"1.3.6.1.4.1.9.9.48.3.1.1"
"ciscoMemoryPoolComplianceRev1"		"1.3.6.1.4.1.9.9.48.3.1.2"
"ciscoMemoryPoolGroup"		"1.3.6.1.4.1.9.9.48.3.2.1"
"ciscoMemoryPoolUtilizationGroup"		"1.3.6.1.4.1.9.9.48.3.2.2"




Vincent-chen 2009-06-18 16:48 发表评论
]]>Communicating with SNMP using C# - The Very Beginning http://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283059.htmlVincent-chenVincent-chenThu, 18 Jun 2009 07:30:00 GMThttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283059.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/283059.htmlhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283059.html#Feedback1http://m.tkk7.com/Vincent-chenxj/comments/commentRss/283059.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/283059.html

Who Should Read This

  1. You want to program SNMP with C# but have no idea for beginning.
  2. You've googled for a while, but don't get a simple working example.
  3. What you're looking for, is just a simple requirement to get a status value from a device through SNMP.

Introduction
My purpose is to get an uint value from a temperature sensor through SNMP. This is a very simple requirement, and I don't want to understand the whole detail of SNMP protocol. In JAVA, there's lot of open source resources for SNMP programming, for example, SNMP4j. How ever, I found no simple guidance for C# SNMP programming. If you have the same problem, you can have following example to start your way toward SNMP.

Pre-requirement
  1. C# Programming Basics
  2. A working SNMP host to communicate with. For example, a temperature sensor, a networked printer or a router with SNMP functions.
Sample SNMP Class
Firstly, you have to add a reference to OLEPRNLIB. You can find it from "Add reference" -> "COM". The path of the dll is located at C:\Windows\System32 by Default.

Here is a sample SNMP Class:

using System;
using System.Collections.Generic;
using System.Text;
using OLEPRNLib;

namespace MrFu
{
public class SimpleSnmp
{
private String hostIp;
private String oid;
private String communityString;

int retries = 1;
int timeout = 3000;

SNMP snmp = new SNMP();

public SimpleSnmp(String hostIp, String communityString, String oid)
{
this.hostIp = hostIp;
this.communityString = communityString;
this.oid = oid;

try
{
snmp.Open(this.hostIp, this.communityString, this.retries, this.timeout);
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
}

}

public String getValue() {
try
{
uint result = snmp.GetAsByte(this.oid);
return result.ToString();
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
return null;
}
}
}
}


Description for the Code

First line you need to look at is:
snmp.Open(this.hostIp, this.communityString, this.retries, this.timeout);
where the "hostIp" is the IP address of the target, of course,

the "communityString" is "public" by default for most SNMP device. If you changed it on device configuration, remember to modify it.

the "retries" and "timeout" indicate how many times the system should retry if connection failed over the milliseconds given by "timeout".

And, That's All to Connect to A Device Through SNMP. COOL!

Second line you might want to know is:
uint result = snmp.GetAsByte(this.oid);
That's the basic way to get the status or value from your host device. You can convert it into String or any thing you like.

To explain in a simple way, the "oid" is the unique id for some status on the device. You can obtain the correct oid from your device manual. For example, the oid of my temperature sensor is:
".1.3.6.1.4.1.3854.1.2.2.1.16.1.3.0"
So you should be able to find some string looks like that from your device suppliers or documents.

For more detailed description of SNMP protocol, you can look into wikipedia.

That's all. So easy, and you can have a first shot of SNMP programming with C# now.


Conclusin
This is quiet a easy way to have a quick look of SNMP progamming with C#. Surely, the detailed packet parsing or other SNMP functions are NOT shown in this post. But that's all I need to solve my problem. And I hope this post can help you, too.

Vincent-chen 2009-06-18 15:30 发表评论
]]>
SQL基本语句http://m.tkk7.com/Vincent-chenxj/articles/245153.htmlVincent-chenVincent-chenTue, 09 Dec 2008 02:02:00 GMThttp://m.tkk7.com/Vincent-chenxj/articles/245153.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/245153.htmlhttp://m.tkk7.com/Vincent-chenxj/articles/245153.html#Feedback0http://m.tkk7.com/Vincent-chenxj/comments/commentRss/245153.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/245153.html掌握SQL四条最基本的数据操作语句:(x)InsertQSelectQUpdate和Delete?br />
   l掌握SQL是数据库用户的宝贵胦(ch) 富。在本文中,我们引g掌握四条最基本的数据操作语句—SQL的核?j)功能—来依次介绍比较操作W、选择断言以及(qing)三值逻辑。当你完成这些学?fn)后Q显然你已经开始算是精通SQL?jin)?br />
  在我们开始之前,先用CREATE TABLE语句来创Z个表Q如?所C)(j)。DDL语句Ҏ(gu)据库对象如表、列和视q行定义。它们ƈ不对表中的行q行处理Q这是因为DDL语句q不处理数据库中实际的数据。这些工作由另一cSQL语句—数据操作语aQDMLQ语句进行处理?br />
  SQL中有四种基本的DML操作QINSERTQSELECTQUPDATE和DELETE。由于这是大多数SQL用户l常用到的,我们有必要在此对它们q行一一说明。在?中我们给Z(jin)一个名为EMPLOYEES的表。其中的每一行对应一个特定的雇员记录。请熟?zhn)q张表,我们在后面的例子中将要用到它?br />
  INSERT语句

  用户可以用INSERT语句一行记录插入到指定的一个表中。例如,要将雇员John Smith的记录插入到本例的表中,可以使用如下语句Q?br />
  INSERT INTO EMPLOYEES VALUES

   ('Smith','John','1980-06-10',

   'Los Angles',16,45000);

  通过q样的INSERT语句Q系l将试着这些值填入到相应的列中。这些列按照我们创徏表时定义的顺序排列。在本例中,W一个?#8220;Smith”填到第一个列LAST_NAME中;W二个?#8220;John”填到第二列FIRST_NAME?#8230;…以此cL?br />
  我们说过pȝ?#8220;试着”值填入,除了(jin)执行规则之外它还要进行类型检查。如果类型不W(如将一个字W串填入到类型ؓ(f)数字的列中)(j)Q系l将拒绝q一ơ操作ƈq回一个错误信息?br />
  如果SQL拒绝?jin)你所填入的一列|语句中其他各列的g不会(x)填入。这是因为SQL提供对事务的支持。一ơ事务将数据库从一U一致性{Ud另一U一致性。如果事务的某一部分p|Q则整个事务都会(x)p|Q系l将?x)被恢复Q或UC为回退Q到此事务之前的状态?br />
   回到原来的INSERT的例子,h意所有的整Ş十进制数都不需要用单引号引hQ而字W串和日期类型的值都要用单引h区别。ؓ(f)?jin)增加可L而在数字间插入逗号会(x)引v错误。记住,在SQL中逗号是元素的分隔W?br />
  同样要注意输入文字值时要用单引号。双引号用来装限界标识W?br />
  对于日期cdQ我们必M用SQL标准日期格式Qyyyy-mm-ddQ,但是在系l中可以q行定义Q以接受其他的格式。当?dng)?000q(f)q,请你最好还是用四位来表示q䆾?br />
  既然你已l理解了(jin)INSERT语句是怎样工作的了(jin)Q让我们转到EMPLOYEES表中的其他部分:(x)

  INSERT INTO EMPLOYEES VALUES

   ('Bunyan','Paul','1970-07-04',

   'Boston',12,70000);

  INSERT INTO EMPLOYEES VALUES

   ('John','Adams','1992-01-21',

   'Boston',20,100000);

  INSERT INTO EMPLOYEES VALUES

   ('Smith','Pocahontas','1976-04-06',

   'Los Angles',12,100000);

  INSERT INTO EMPLOYEES VALUES

   ('Smith','Bessie','1940-05-02',

   'Boston',5,200000);

  INSERT INTO EMPLOYEES VALUES

   ('Jones','Davy','1970-10-10',

   'Boston',8,45000);

  INSERT INTO EMPLOYEES VALUES

   ('Jones','Indiana','1992-02-01',

   'Chicago',NULL,NULL);

  在最后一中Q我们不知道Jones先生的工薪别和q薪Q所以我们输入NULLQ不要引P(j)。NULL是SQL中的一U特D情况,我们以后进行详l的讨论。现在我们只需认ؓ(f)NULL表示一U未知的倹{?br />
  有时Q像我们刚才所讨论的情况,我们可能希望Ҏ(gu)一些而不是全部的列进行赋倹{除?jin)对要省略的列输入NULL外,q可以采用另外一UINSERT语句Q如下:(x)

  INSERT INTO EMPLOYEES(

   FIRST_NAME, LAST_NAME,

   HIRE_DATE, BRANCH_OFFICE)

  VALUE(

   'Indiana','Jones',

   '1992-02-01','Indianapolis');

  q样Q我们先在表名之后列Zpd列名。未列出的列中将自动填入~省|如果没有讄~省值则填入NULL。请注意我们改变?sh)(jin)列的顺序,而值的序要对应新的列的顺序。如果该语句中省略了(jin)FIRST_NAME和LAST_NAME(q两规定不能ؓ(f)I)(j)QSQL操作失败?br />
  让我们来看一看上qINSERT语句的语法图Q?br />
  INSERT INTO table

   [(column { ,column})]

  VALUES

   (columnvalue [{,columnvalue}]);

  和前一文章中一P我们用方括号来表C可选项Q大括号表示可以重复Lơ数的项Q不能在实际的SQL语句中用这些特D字W)(j)。VALUE子句和可选的列名列表中必M用圆括号?br />
  SELECT语句

  SELECT语句可以从一个或多个表中选取特定的行和列。因为查询和(g)索数据是数据库管理中最重要的功能,所以SELECT语句在SQL中是工作量最大的部分。实际上Q仅仅是讉K数据库来分析数据q生成报表的人可以对其他SQL语句一H不通?br />
  SELECT语句的结果通常是生成另外一个表。在执行q程中系l根据用L(fng)标准从数据库中选出匚w的行和列Qƈ结果放C(f)时的表中。在直接SQLQdirect SQLQ中Q它?yu)结果显C在l端的显C屏上,或者将l果送到打印机或文g中。也可以l合其他SQL语句来将l果攑ֈ一个已知名U的表中?br />
  SELECT语句功能强大。虽然表面上看来它只用来完成本文W一部分中提到的关系代数q算“选择”Q或U?#8220;限制”Q,但实际上它也可以完成其他两种关系q算?#8220;投媄(jing)”?#8220;q接”QSELECT语句q可以完成聚合计ƈҎ(gu)据进行排序?br />
  SELECT语句最单的语法如下Q?br />
  SELECT columns FROM tables;

  当我们以q种形式执行一条SELECT语句Ӟpȝq回由所选择的列以及(qing)用户选择的表中所有指定的行组成的一个结果表。这是实现关系投媄(jing)q算的一个Ş式?br />
  让我们看一下用图1中EMPLOYEES表的一些例子(q个表是我们以后所有SELECT语句实例都要使用的。而我们在?和图3中给Z(jin)查询的实际结果。我们将在其他的例子中用这些结果)(j)?br />
  假设你想查看雇员工作部门的列表。那下面是你所需要编写的SQL查询Q?br />
  SELECT BRANCH_OFFICE FROM EMPLOYEES;

  以上SELECT语句的执行将产生如图2中表2所C的l果?br />
  ׃我们在SELECT语句中只指定?jin)一个列Q所以我们的l果表中也只有一个列。注意结果表中具有重复的行,q是因ؓ(f)有多个雇员在同一部门工作Q记住SQL从所选的所有行中将D回)(j)。要消除l果中的重复行,只要在SELECT语句中加上DISTINCT子句Q?br />
  SELECT DISTINCT BRANCH_OFFICE

  FROM EMPLOYEES;

  q次查询的结果如?所C?br />
  现在已经消除?jin)重复的行,但结果ƈ不是按照序排列的。如果你希望以字母表序结果列出又该怎么做呢Q只要用ORDER BY子句可以按照升序或降序来排列结果:(x)

  SELECT DISTINCT BRANCH_OFFICE

  FROM EMPLOYEES

  ORDER BY BRANCH_OFFICE ASC;

  q一查询的结果如?所C。请注意在ORDER BY之后是如何放|列名BRANCH _OFFICE的,q就是我们想要对其进行排序的列。ؓ(f)什么即使是l果表中只有一个列时我们也必须指出列名呢?q是因ؓ(f)我们q能够按照表中其他列q行排序Q即使它们ƈ不显C出来。列名BRANCH_ OFFICE之后的关键字ASC表示按照升序排列。如果你希望以降序排列,那么可以用关键字DESC?br />
  同样我们应该指出ORDER BY子句只将临时表中的结果进行排序;q不影响原来的表?br />
  假设我们希望得到按部门排序ƈ从工资最高的雇员到工资最低的雇员排列的列表。除?jin)工资括号中的内容,我们q希望看到按照聘用时间从最q聘用的雇员开始列出的列表。以下是你将要用到的语句Q?br />
  SELECT BRANCH_OFFICE,FIRST_NAME,

   LAST_NAME,SALARY,HIRE_DATE

  FROM EMPLOYEES

  ORDER BY SALARY DESC,

   HIRE_DATE DESC;

  q里我们q行?jin)多列的选择和排序。排序的优先U由语句中的列名序所军_。SQL先对列出的W一个列q行排序。如果在W一个列中出C(jin)重复的行Ӟq些行将被按照第二列q行排序Q如果在W二列中又出C(jin)重复的行Ӟq些行又被按照W三列进行排?#8230;…如此cL。这ơ查询的l果如表5所C?br />
  一个很长的表中的所有列名写出来是一件相当麻?ch)的事,所以SQL允许在选择表中所有的列时使用*P(x)

  SELECT * FROM EMPLOYEES;

  q次查询q回整个EMPLOYEES表,如表1所C?br />
   下面我们对开始时l出的SELECT语句的语法进行一下更斎ͼ竖直U表CZ个可选项Q允许在其中选择一V)(j)Q?br />
  SELECT [DISTINCT]

   (column [{, columns}])| *

  FROM table [ {, table}]

  [ORDER BY column [ASC] | DESC

   [ {, column [ASC] | DESC }]];

  定义选择标准

  在我们目前所介绍的SELECT语句中,我们对结果表中的列作Z(jin)选择但返回的是表中所有的行。让我们看一下如何对SELECT语句q行限制使得它只q回希望得到的行Q?br />
  SELECT columns FROM tables [WHERE predicates];

  WHERE子句Ҏ(gu)件进行了(jin)讄Q只有满x(chng)件的行才被包括到l果表中。这些条件由断言QpredicateQ进行指定(断言指出?jin)关于某件事情的一U可能的事实Q。如果该断言对于某个l定的行成立Q该行将被包括到l果表中Q否则该行被忽略。在SQL语句中断a通常通过比较来表C。例如,假如你需要查询所有姓为Jones的职员,则可以用以下SELECT语句Q?br />
  SELECT * FROM EMPLOYEES

  WHERE LAST_NAME = 'Jones';

  LAST_NAME = 'Jones'部分是断言。在执行该语句时QSQL每一行的LAST_NAME列与“Jones”q行比较。如果某一职员的姓?#8220;Jones”Q即断言成立Q该职员的信息将被包括到l果表中Q见?Q?br />
  使用最多的六种比较

  我们上例中的断言包括一U基?#8220;{?#8221;的比较(LAST_NAME = 'Jones'Q,但是SQL断言q可以包含其他几U类型的比较。其中最常用的ؓ(f)Q?br />
  {于 =

  不等?<>

  于 <

  大于 >

  于或等?<=

  大于或等?>=

  下面l出?jin)不是基于等值比较的一个例子:(x)

  SELECT * FROM EMPLOYEES

  WHERE SALARY > 50000;

  q一查询返回年薪高?sh)?50,000.00的职员(参见?Q?br />
  逻辑q接W?br />
  有时我们需要定义一条不止一U断a的SELECT语句。D例来_(d)如果你仅仅想查看Davy Jones的信息的话,?中的l果是不正的。ؓ(f)?jin)进一步定义一个WHERE子句Q用户可以用逻辑q接WANDQOR和NOT。ؓ(f)?jin)只得到职员Davy Jones的记录,用户可以输入如下语句Q?br />
  SELECT * FROM EMPLOYEES

  WHERE LAST_NAME = 'Jones' AND FIRST_NAME = 'Davy';

  在本例中Q我们通过逻辑q接WAND两个断aq接h。只有两个断a都满x(chng)整个表达式才?x)满뀂如果用户需要定义一个SELECT语句来得当其中M一Ҏ(gu)立就满条gӞ可以使用ORq接W:(x)

  SELECT * FROM EMPLOYEES

  WHERE LAST_NAME = 'Jones' OR LAST_NAME = 'Smith';

  有时定义一个断a的最好方法是通过相反的描q来说明。如果你惌查看除了(jin)Boston办事处的职员?sh)外的其他所有职员的信息Ӟ你可以进行如下的查询Q?br />
  SELECT * FROM EMPLOYEES

  WHERE NOT(BRANCH_OFFICE = 'Boston');

  关键字NOT后面跟着用圆括号括v来的比较表达式。其l果是对l果取否定。如果某一职员所在部门的办事处在BostonQ括号内的表辑ּq回trueQ但是NOT操作W将该值取反,所以该行将不被选中?br />
  断言可以与其他的断言嵌套使用。ؓ(f)?jin)保证它们以正确的顺序进行求|可以用括号将它们括v来:(x)

  SELECT * FROM EMPLOYEES

  WHERE (LAST_NAME = 'Jones'

  AND FIRST_NAME = 'Indiana')

  OR (LAST_NAME = 'Smith'

  AND FIRST_NAME = 'Bessie');

  SQL沿用数学上标准的表达式求值的U定—圆括号内的表达式将最先进行求|其他表达式将从左到右q行求倹{?br />
  以上寚w辑q接W进行了(jin)说明Q在对下面的内容q行说明之前Q我们再一ơ对SELECT语句的语法进行更斎ͼ(x)

  SELECT [DISTINCT]

   (column [{, column } ] )| *

  FROM table [ { , table} ]

  [ORDER BY column [ASC] | [DESC

  [{ , column [ASC] | [DESC } ] ]

  WHERE predicate [ { logical-connector predicate } ];

  NULL和三值逻辑

  在SQL中NULL是一个复杂的话题Q关于NULL的详l描q更适合于在SQL的高U教E而不是现在的入门教程中进行介l。但׃NULL需要进行特D处理,q且你也很可能会(x)遇到它,所以我们还是简略地q行一下说明?br />
  首先Q在断言中进行NULL判断旉要特D的语法。例如,如果用户需要显C所有年薪未知的职员的全部信息,用户可以使用如下SELECT语句Q?br />
  SELECT * FROM EMPLOYEES

  WHERE SALARY IS NULL;

  相反Q如果用户需要所有已知年薪数据的职员的信息,你可以用以下语句:(x)

  SELECT * FROM EMPLOYEES

  WHERE SALARY IS NOT NULL;

  h意我们在列名之后使用?jin)关键字IS NULL或IS NOT NULLQ而不是标准的比较形式QCOLUMN = NULL、COLUMN <> NULL或是逻辑操作WNOTQNULLQ?br />
  q种形式相当单。但当你不明地试NULLQ而它们确实存在)(j)Ӟ事情?x)变得很混ؕ?br />
  例如Q回q头来看我们?中的EM-PLOYEES表,可以看到Indiana Jones的工薪等U或q薪值都是未知的。这两个列都包含NULL。可以想象运行如下的查询Q?br />
  SELECT * FROM EMPLOYEES

  WHERE GRADE <= SALARY;

  此时QIndiana Jones应该出现在结果表中。因为NULL都是相等的,所以可以想象它们是能够通过GRADE于{于SALARY的检查的。这其实是一个毫无疑义的查询Q但是ƈ没有关系。SQL允许q行q样的比较,只要两个列都是数字类型的。然而,Indiana Jonesq没有出现在查询的结果中Qؓ(f)什么?

  正如我们早先提到q的QNULL表示未知的|而不是象某些人所惌的那栯CZ个ؓ(f)NULL的|(j)。对于SQL来说意味着q个值是未知的,而只要这个gؓ(f)未知Q就不能其与其他值比较(即其他g是NULLQ。所以SQL允许除了(jin)在true 和false之外q有W三U类型的真|UC?#8220;非确?#8221;QunknownQ倹{?br />
  如果比较的两辚w是NULLQ整个断ap认ؓ(f)是非定的。将一个非定断言取反或用AND或OR与其他断aq行合ƈ之后Q其l果仍是非确定的。由于结果表中只包括断言gؓ(f)“?#8221;的行Q所以NULL不可能满(g)查。从而需要用特D的操作WIS NULL和IS NOT NULL?br />
  UPDATE语句

  UPDATE语句允许用户在已知的表中对现有的行进行修攏V?br />
  例如Q我们刚刚发现Indiana Jones的等Uؓ(f)16Q工资ؓ(f)$40,000.00Q我们可以通过下面的SQL语句Ҏ(gu)据库q行更新Qƈ清除那些?ch)h的NULLQ?br />
  UPDATE EMPLOYEES

  SET GRADE = 16, SALARY = 40000

  WHERE FIRST_NAME = 'Indiana'

   AND LAST_NAME = 'Jones';

  上面的例子说明了(jin)一个单行更斎ͼ但是UPDATE语句可以对多行进行操作。满WHERE条g的所有行都将被更新。如果,你想让Boston办事处中的所有职员搬到New YorkQ你可以使用如下语句Q?br />
  UPDATE EMPLOYEES

  SET BRANCH_OFFICE = 'New York'

  WHERE BRANCH_OFFICE = 'Boston';

  如果忽略WHERE子句,表中所有行中的部门值都被更新?New York'?br />
  UPDATE语句的语法流囑֦下面所C:(x)

  UPDATE table

  SET column = value [{, column = value}]

  [ WHERE predicate [ { logical-connector predicate}]];

  DELETE语句

  DELETE语句用来删除已知表中的行。如同UPDATE语句中一P所有满WHERE子句中条件的行都被删除。由于SQL中没有UNDO语句或是“你确认删除吗Q?#8221;之类的警告,在执行这条语句时千万要小?j)。如果决定取消Los Angeles办事处ƈ解雇办事处的所有职员,q一卑鄙的工作可以由以下q条语句来实玎ͼ(x)

  DELETE FROM EMPLOYEES

  WHERE BRANCH_OFFICE = 'Los Angeles';

  如同UPDATE语句中一P省略WHERE子句得操作施加到表中所有的行?br />
  DELETE语句的语法流囑֦下面所C:(x)

  DELETE FROM table

  [WHERE predicate [ { logical-connector predicate} ] ];

  现在我们完成?jin)数据操作语aQDMLQ的主要语句的介l。我们ƈ没有对SQL能完成的所有功能进行说明。SQLq提供了(jin)许多的功能,如求q_倹{求和以?qing)其他对表中数据的计,此外SQLq能完成从多个表中进行查询(多表查询Q或UC接)(j)的工作。这U语aq允怽使用GRANT和REVOKE命o(h)控制使用者的数据讉K权限?/span>

Vincent-chen 2008-12-09 10:02 发表评论
]]>
JSF问题集锦http://m.tkk7.com/Vincent-chenxj/articles/243633.htmlVincent-chenVincent-chenMon, 01 Dec 2008 01:55:00 GMThttp://m.tkk7.com/Vincent-chenxj/articles/243633.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/243633.htmlhttp://m.tkk7.com/Vincent-chenxj/articles/243633.html#Feedback0http://m.tkk7.com/Vincent-chenxj/comments/commentRss/243633.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/243633.html1.如何l束session?   
  • 你可以用session?nbsp;invalidateҎ(gu) .   
  • 下面是一个从actionҎ(gu)中结束session的例? :   
  • public String logout() {    
      FacesContext fc 
    = FacesContext.getCurrentInstance();    
      HttpSession session 
    = (HttpSession) fc.getExternalContext().getSession(false);    
      session.invalidate();    
      
    return "login_page";    
    }
       

     

  • 下面的代码片D늤例了(jin)如何在JSP面中结束session:   
  • <% session.invalidate(); %>    
    <c:redirect url="loginPage.jsf" />    
       

  •   
  • 2.如何在JSP面中访问web.xml中的初始化参?   
  • 你可以用预定义的JSF EL变量  initParam来访?   
  • 例如,如果你有:   
  •  

    <context-param>    
     
    <param-name>productId</param-name>    
     
    <param-value>2004Q4</param-value>    
    </context-param>    

     

  • 你可以用她 #{initParam['productId']}来访?nbsp;.例如:   
  • Product Id: <h:outputText value="#{initParam['productId']}"/>   
  •   
  •   
  • 3.如何从java代码中访问web.xml 中的初始化参?   
  • 你可以用externalContext?nbsp;getInitParameter Ҏ(gu)得到他们.例如 如果你的参数如下:   
  •  

    <context-param>    
     
    <param-name>connectionString</param-name>    
     
    <param-value>jdbc:oracle:thin:scott/tiger@cartman:1521:O901DB</param-value>    
    </context-param>    

     

  • 你可以用下面代码访问connectionString :   
  • FacesContext fc = FacesContext.getCurrentInstance();String connection = fc.getExternalContext().getInitParameter("connectionString");    
  •   
  •   
  • 4.如何从backing bean中得到当前页面的URL?   
  • 你可以通过FacesContext得到一个Http Request对象的引?如下:   
  • FacesContext fc = FacesContext.getCurrentInstance();HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();    
  • 然后使用普通的requestҎ(gu)来得到\径信?q可以用另外一U方?   
  • context.getViewRoot().getViewId();   
  • 返回你当前JSP(JSF view IDs 基本上只是JSP path names)面的名?   
  •   
  •   
  • 5.如何d上下文\径到outputLink的URL?   
  • 在当前的JSF实现?当在outputLink 中定义的路径?/'开始时,没有d上下文\径到URL?要I补该问题请在URL中?nbsp;#{facesContext.externalContext.requestContextPath} 前缀.例如:   
  • <h:outputLink value="#{facesContext.externalContext.requestContextPath}/myPage.faces">   
  •   
  •   
  • 6.如何使用URL字符串来传递参数到JSFE序?   
  • 如果你有下面的URL: http://your_server/your_app/product.jsf?id=777, 你可以用下面的代码来访问所传递的参数:     
  • FacesContext fc = FacesContext.getCurrentInstance();String id = (String) fc.getExternalContext().getRequestParameterMap().get("id");    
  • 在JSF面?你也可以使用预定义的变量讉K同样的参?例如:    
  • <h:outputText value="#{param['id']}" />   
  • 注意: 你必ȝ接调用该JSF面,q且使用servlet 映射 (mapping).   
  •   
  •   
  • 7.如何在页面重新蝲入的时候保留h:inputSecret中的密码?   
  • 讄redisplay=true, it is false by default.   
  •     
  •   
  • 8.如何使用h:outputText输出HTML标签?   
  •   
  • h:outputText有一?nbsp; escape 属性用来处理html 标签. 默认gؓ(f)true.q意味着所有特D的W合都被转义?&'代码. L(fng)下面CZ:  <h:outputText value="<b>This is a text</b>"/> 打印的结果是:  <b>This is a text</b>  ?nbsp;<h:outputText escape="false" value="<b>This is a text</b>"/>  打印的结果是:  This is a text  当用L(fng)击Command Link后如何显C确认对话框?   
  • h:commandLink指定?nbsp;onclick 属性ؓ(f)内部使用. 因此你不可以使用她了(jin), 该问题已l在JSF1.2中修复了(jin),对于JSF1.2以前的版?你可以在onclick以前使用  onmousedown 事g  <script  language="javascript">  function ConfirmDelete(link) {    var delete = confirm('Do you want to Delete?');    if (delete == true) {      link.onclick();    }  }</script>   
  • <h:commandLink action="delete" onmousedown="return ConfirmDelete(this);">  <h:outputText value="delete it"/></h:commandLink>   
  •     
  •   
  • 9.在调用ValueChangeListener Ҏ(gu)后如何重新装载页?   
  • ?nbsp;ValueChangeListener的最?调用  FacesContext.getCurrentInstance().renderResponse()   
  • 如何实现"L(fng)?.."面? 在客L(fng)实现可能很简?你可以包装JSP面(或者你惌隐藏的一部分)C个div?然后你可以添加更多div,当用L(fng)?yn)L交按钮时q些div出现.q些div可以包含gif动画和其他内? 场景:当用L(fng)?yn)L?调用JS函数,该函数隐藏页面ƈ且显C?/span>"L(fng)?.."div.你可以用CSS来自定义外观:下面是一个正常工作的例子: <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>   
  • <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>    
    <f:loadBundle basename="demo.bundle.Messages" var="Message"/>    
    <html>    
    <head>    
      
    <title>Input Name Page</title>    
      
    <script>    
        function gowait() {    
          document.getElementById("main").style.visibility="hidden";    
          document.getElementById("wait").style.visibility="visible";    
        }    
       
    </script>    
           
     
    </head>    
     
    <body bgcolor="white">    
      
    <f:view>    
        
    <div id="main">    
           
    <h1><h:outputText value="#{Message.inputname_header}"/></h1>    
           
    <h:messages style="color: red"/>    
           
    <h:form id="helloForm">    
             
    <h:outputText value="#{Message.prompt}"/>    
             
    <h:inputText id="userName" value="#{GetNameBean.userName}" required="true">    
               
    <f:validateLength minimum="2" maximum="20"/>    
             
    </h:inputText>    
             
    <h:commandButton onclick="gowait()" id="submit"   
                   action
    ="#{GetNameBean.action}" value="Say Hello" />    
           
    </h:form>    
        
    </div>    
        
    <div id="wait" style="visibility:hidden; position: absolute; top: 0; left: 0">    
           
    <table width="100%" height ="300px">    
             
    <tr>    
               
    <td align="center" valign="middle">    
                 
    <h2>Please, wait</h2>    
               
    </td>    
             
    </tr>    
           
    </table>    
        
    </div>    
      
    </f:view>    
     
    </body>    
    </html>     
       

    如果你想有一个动画gif囄?/span>"L(fng)?.."?当表单提交后该图片应该从新加?因此,再一ơ指定图片的id,q且dl过一D|间g时后重新加蝲的代?下面是个例子: <script>   

     

     function gowait() {    
       document.getElementById("main").style.visibility="hidden";    
       document.getElementById("wait").style.visibility="visible";    
       window.setTimeout('showProgress()', 500);    
     }    
      function showProgress(){    
       var wg = document.getElementById("waitgif");    
       wg.src=wg.src;    
     }    
    </script>    
    .    
    <img id="waitgif" src="animated.gif">   


    Vincent-chen 2008-12-01 09:55 发表评论
    ]]>
    jsfl束sessionhttp://m.tkk7.com/Vincent-chenxj/articles/243401.htmlVincent-chenVincent-chenSat, 29 Nov 2008 05:06:00 GMThttp://m.tkk7.com/Vincent-chenxj/articles/243401.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/243401.htmlhttp://m.tkk7.com/Vincent-chenxj/articles/243401.html#Feedback0http://m.tkk7.com/Vincent-chenxj/comments/commentRss/243401.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/243401.html 下面是一个从actionҎ(gu)中结束session的例? :

     

    public String logout() {

      FacesContext fc 
    = FacesContext.getCurrentInstance();
      HttpSession session 
    = (HttpSession) fc.getExternalContext().getSession(false);
      session.invalidate();
      
    return "login_page";
    }
      

     

    下面的代码片D늤例了(jin)如何在JSP面中结束session:

    
    
    <% session.invalidate(); %>
    <c:redirect url="loginPage.jsf" /> 


    Vincent-chen 2008-11-29 13:06 发表评论
    ]]>
    操作word的解x(chng)?/title><link>http://m.tkk7.com/Vincent-chenxj/articles/243382.html</link><dc:creator>Vincent-chen</dc:creator><author>Vincent-chen</author><pubDate>Sat, 29 Nov 2008 02:04:00 GMT</pubDate><guid>http://m.tkk7.com/Vincent-chenxj/articles/243382.html</guid><wfw:comment>http://m.tkk7.com/Vincent-chenxj/comments/243382.html</wfw:comment><comments>http://m.tkk7.com/Vincent-chenxj/articles/243382.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/Vincent-chenxj/comments/commentRss/243382.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/Vincent-chenxj/services/trackbacks/243382.html</trackback:ping><description><![CDATA[     摘要: /** *//**            *   i料ipExcelファイル書く            *  &nb...  <a href='http://m.tkk7.com/Vincent-chenxj/articles/243382.html'>阅读全文</a><img src ="http://m.tkk7.com/Vincent-chenxj/aggbug/243382.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/Vincent-chenxj/" target="_blank">Vincent-chen</a> 2008-11-29 10:04 <a href="http://m.tkk7.com/Vincent-chenxj/articles/243382.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POI 数据导出到Word的实?/title><link>http://m.tkk7.com/Vincent-chenxj/articles/243381.html</link><dc:creator>Vincent-chen</dc:creator><author>Vincent-chen</author><pubDate>Sat, 29 Nov 2008 01:55:00 GMT</pubDate><guid>http://m.tkk7.com/Vincent-chenxj/articles/243381.html</guid><wfw:comment>http://m.tkk7.com/Vincent-chenxj/comments/243381.html</wfw:comment><comments>http://m.tkk7.com/Vincent-chenxj/articles/243381.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://m.tkk7.com/Vincent-chenxj/comments/commentRss/243381.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/Vincent-chenxj/services/trackbacks/243381.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">import</span><span style="color: #000000"> java.io.</span><span style="color: #000000">*</span><span style="color: #000000">; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> java.util.</span><span style="color: #000000">*</span><span style="color: #000000">; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.apache.poi.poifs.filesystem.</span><span style="color: #000000">*</span><span style="color: #000000">; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.apache.poi.util.LittleEndian; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_148_851_Open_Image" onclick="this.style.display='none'; Codehighlighter1_148_851_Open_Text.style.display='none'; Codehighlighter1_148_851_Closed_Image.style.display='inline'; Codehighlighter1_148_851_Closed_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_148_851_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_148_851_Closed_Text.style.display='none'; Codehighlighter1_148_851_Open_Image.style.display='inline'; Codehighlighter1_148_851_Open_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> WordTest </span><span id="Codehighlighter1_148_851_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://m.tkk7.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_148_851_Open_Text"><span style="color: #000000">{ <br /> <img id="Codehighlighter1_169_172_Open_Image" onclick="this.style.display='none'; Codehighlighter1_169_172_Open_Text.style.display='none'; Codehighlighter1_169_172_Closed_Image.style.display='inline'; Codehighlighter1_169_172_Closed_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_169_172_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_169_172_Closed_Text.style.display='none'; Codehighlighter1_169_172_Open_Image.style.display='inline'; Codehighlighter1_169_172_Open_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> WordTest() </span><span id="Codehighlighter1_169_172_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://m.tkk7.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_169_172_Open_Text"><span style="color: #000000">{ <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"> <br /> <img id="Codehighlighter1_240_752_Open_Image" onclick="this.style.display='none'; Codehighlighter1_240_752_Open_Text.style.display='none'; Codehighlighter1_240_752_Closed_Image.style.display='inline'; Codehighlighter1_240_752_Closed_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_240_752_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_240_752_Closed_Text.style.display='none'; Codehighlighter1_240_752_Open_Image.style.display='inline'; Codehighlighter1_240_752_Open_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">boolean</span><span style="color: #000000"> writeWordFile(String path, String content) </span><span id="Codehighlighter1_240_752_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://m.tkk7.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_240_752_Open_Text"><span style="color: #000000">{ <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">boolean</span><span style="color: #000000"> w </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">false</span><span style="color: #000000">; <br /> <img id="Codehighlighter1_267_689_Open_Image" onclick="this.style.display='none'; Codehighlighter1_267_689_Open_Text.style.display='none'; Codehighlighter1_267_689_Closed_Image.style.display='inline'; Codehighlighter1_267_689_Closed_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_267_689_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_267_689_Closed_Text.style.display='none'; Codehighlighter1_267_689_Open_Image.style.display='inline'; Codehighlighter1_267_689_Open_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">try</span><span style="color: #000000"> </span><span id="Codehighlighter1_267_689_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://m.tkk7.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_267_689_Open_Text"><span style="color: #000000">{ <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #008000">//</span><span style="color: #008000"> byte b[] = content.getBytes("ISO-8859-1"); </span><span style="color: #008000"><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">byte</span><span style="color: #000000"> b[] </span><span style="color: #000000">=</span><span style="color: #000000"> content.getBytes(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />ByteArrayInputStream bais </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> ByteArrayInputStream(b); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />POIFSFileSystem fs </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> POIFSFileSystem(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />DirectoryEntry directory </span><span style="color: #000000">=</span><span style="color: #000000"> fs.getRoot(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />DocumentEntry de </span><span style="color: #000000">=</span><span style="color: #000000"> directory.createDocument(</span><span style="color: #000000">"</span><span style="color: #000000">WordDocument</span><span style="color: #000000">"</span><span style="color: #000000">, bais); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />FileOutputStream ostream </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> FileOutputStream(path); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />fs.writeFilesystem(ostream); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />bais.close(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />ostream.close(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_713_738_Open_Image" onclick="this.style.display='none'; Codehighlighter1_713_738_Open_Text.style.display='none'; Codehighlighter1_713_738_Closed_Image.style.display='inline'; Codehighlighter1_713_738_Closed_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_713_738_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_713_738_Closed_Text.style.display='none'; Codehighlighter1_713_738_Open_Image.style.display='inline'; Codehighlighter1_713_738_Open_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />}</span></span><span style="color: #000000"> </span><span style="color: #0000ff">catch</span><span style="color: #000000"> (IOException e) </span><span id="Codehighlighter1_713_738_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://m.tkk7.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_713_738_Open_Text"><span style="color: #000000">{ <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />e.printStackTrace(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"> <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">return</span><span style="color: #000000"> w; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"> <br /> <img id="Codehighlighter1_793_848_Open_Image" onclick="this.style.display='none'; Codehighlighter1_793_848_Open_Text.style.display='none'; Codehighlighter1_793_848_Closed_Image.style.display='inline'; Codehighlighter1_793_848_Closed_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_793_848_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_793_848_Closed_Text.style.display='none'; Codehighlighter1_793_848_Open_Image.style.display='inline'; Codehighlighter1_793_848_Open_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String[] args)</span><span id="Codehighlighter1_793_848_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://m.tkk7.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_793_848_Open_Text"><span style="color: #000000">{ <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">boolean</span><span style="color: #000000"> b </span><span style="color: #000000">=</span><span style="color: #000000"> writeWordFile(</span><span style="color: #000000">"</span><span style="color: #000000">E://test.doc</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">"</span><span style="color: #000000">hello</span><span style="color: #000000">"</span><span style="color: #000000">); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"> <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"> <br /> <img id="Codehighlighter1_854_5064_Open_Image" onclick="this.style.display='none'; Codehighlighter1_854_5064_Open_Text.style.display='none'; Codehighlighter1_854_5064_Closed_Image.style.display='inline'; Codehighlighter1_854_5064_Closed_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_854_5064_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_854_5064_Closed_Text.style.display='none'; Codehighlighter1_854_5064_Open_Image.style.display='inline'; Codehighlighter1_854_5064_Open_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span id="Codehighlighter1_854_5064_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/**/</span><span id="Codehighlighter1_854_5064_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000"> <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />public String extractText(InputStream in) throws IOException { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />ArrayList text = new ArrayList(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />POIFSFileSystem fsys = new POIFSFileSystem(in); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />DocumentEntry headerProps = (DocumentEntry) fsys.getRoot().getEntry("WordDocument"); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />DocumentInputStream din = fsys.createDocumentInputStream("WordDocument"); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />byte[] header = new byte[headerProps.getSize()]; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />din.read(header); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />din.close(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />// Prende le informazioni dall'header del documento <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int info = LittleEndian.getShort(header, 0xa); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />boolean useTable1 = (info & 0x200) != 0; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />//boolean useTable1 = true; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />// Prende informazioni dalla piece table <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int complexOffset = LittleEndian.getInt(header, 0x1a2); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />//int complexOffset = LittleEndian.getInt(header); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />String tableName = null; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />if (useTable1) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />tableName = "1Table"; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} else { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />tableName = "0Table"; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />DocumentEntry table = (DocumentEntry) fsys.getRoot().getEntry(tableName); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />byte[] tableStream = new byte[table.getSize()]; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />din = fsys.createDocumentInputStream(tableName); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />din.read(tableStream); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />din.close(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />din = null; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />fsys = null; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />table = null; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />headerProps = null; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int multiple = findText(tableStream, complexOffset, text); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />StringBuffer sb = new StringBuffer(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int size = text.size(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />tableStream = null; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />for (int x = 0; x < size; x++) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />WordTextPiece nextPiece = (WordTextPiece) text.get(x); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int start = nextPiece.getStart(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int length = nextPiece.getLength(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />boolean unicode = nextPiece.usesUnicode(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />String toStr = null; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />if (unicode) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />toStr = new String(header, start, length * multiple, "UTF-16LE"); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} else { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />toStr = new String(header, start, length, "ISO-8859-1"); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />sb.append(toStr).append(" "); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />return sb.toString(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />private static int findText(byte[] tableStream, int complexOffset, ArrayList text) <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />throws IOException { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />//actual text <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int pos = complexOffset; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int multiple = 2; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />//skips through the prms before we reach the piece table. These contain data <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />//for actual fast saved files <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />while (tableStream[pos] == 1) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />pos++; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int skip = LittleEndian.getShort(tableStream, pos); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />pos += 2 + skip; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />if (tableStream[pos] != 2) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />throw new IOException("corrupted Word file"); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} else { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />//parse out the text pieces <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int pieceTableSize = LittleEndian.getInt(tableStream, ++pos); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />pos += 4; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int pieces = (pieceTableSize - 4) / 12; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />for (int x = 0; x < pieces; x++) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int filePos = <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />LittleEndian.getInt(tableStream, pos + ((pieces + 1) * 4) + (x *<img src="http://m.tkk7.com/images/forum/smiles/icon_cool.gif"/> + 2); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />boolean unicode = false; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />if ((filePos & 0x40000000) == 0) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />unicode = true; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} else { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />unicode = false; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />multiple = 1; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />filePos &= ~(0x40000000); //gives me FC in doc stream <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />filePos /= 2; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int totLength = <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />LittleEndian.getInt(tableStream, pos + (x + 1) * 4) <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />- LittleEndian.getInt(tableStream, pos + (x * 4)); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />WordTextPiece piece = new WordTextPiece(filePos, totLength, unicode); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />text.add(piece); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />return multiple; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />public static void main(String[] args){ <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />WordTest w = new WordTest(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />POIFSFileSystem ps = new POIFSFileSystem(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />try{ <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />File file = new File("C:\\test.doc"); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />InputStream in = new FileInputStream(file); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />String s = w.extractText(in); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />System.out.println(s); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />}catch(Exception e){ <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />e.printStackTrace(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />public boolean writeWordFile(String path, String content) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />boolean w = false; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />try { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />// byte b[] = content.getBytes("ISO-8859-1"); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />byte b[] = content.getBytes(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />ByteArrayInputStream bais = new ByteArrayInputStream(b); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />POIFSFileSystem fs = new POIFSFileSystem(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />DirectoryEntry directory = fs.getRoot(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />DocumentEntry de = directory.createDocument("WordDocument", bais); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />FileOutputStream ostream = new FileOutputStream(path); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />fs.writeFilesystem(ostream); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />bais.close(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />ostream.close(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} catch (IOException e) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />e.printStackTrace(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />return w; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />class WordTextPiece { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />private int _fcStart; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />private boolean _usesUnicode; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />private int _length; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />public WordTextPiece(int start, int length, boolean unicode) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />_usesUnicode = unicode; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />_length = length; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />_fcStart = start; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />public boolean usesUnicode() { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />return _usesUnicode; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />public int getStart() { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />return _fcStart; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />public int getLength() { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />return _length; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /></span><span style="color: #008000">*/</span></span><span style="color: #000000"> </span></div> <img src ="http://m.tkk7.com/Vincent-chenxj/aggbug/243381.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/Vincent-chenxj/" target="_blank">Vincent-chen</a> 2008-11-29 09:55 <a href="http://m.tkk7.com/Vincent-chenxj/articles/243381.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>лǵվܻԴȤ</p> <a href="http://m.tkk7.com/" title="亚洲av成人片在线观看">亚洲av成人片在线观看</a> <div class="friend-links"> </div> </div> </footer> վ֩ģ壺 <a href="http://tha2008.com" target="_blank">videosbestsexձ</a>| <a href="http://52ku6.com" target="_blank">ŮƵѹۿվ</a>| <a href="http://wlzp88.com" target="_blank">99re6߾ƷƵѲ</a>| <a href="http://cn-taoqigui.com" target="_blank">avҹƷһ </a>| <a href="http://littlevv.com" target="_blank">Ҹ24p</a>| <a href="http://kppp4.com" target="_blank">߹ۿHַ</a>| <a href="http://868664.com" target="_blank">vavavaĻ</a>| <a href="http://ninggelang.com" target="_blank">붯xxxxx</a>| <a href="http://js-jiarui.com" target="_blank">Ʒ</a>| <a href="http://yuezhaoming.com" target="_blank">޿ƬƵ</a>| <a href="http://blzcn.com" target="_blank">ѲƵ</a>| <a href="http://33dh2.com" target="_blank">͵ͼƬ</a>| <a href="http://bjyaao.com" target="_blank">ѹۿ91Ƶ</a>| <a href="http://arkinbokis.com" target="_blank">պ޴߶ȸ</a>| <a href="http://zcrencai.com" target="_blank">Ʒhdѹۿ</a>| <a href="http://beijinzhongliuyiyuan.com" target="_blank">ҹˬˬˬWWWƵʮ˽ </a>| <a href="http://wwwkckc.com" target="_blank">ѹۿ</a>| <a href="http://5kee.com" target="_blank">ձvaҹĻһ</a>| <a href="http://2266511.com" target="_blank">Ӱ߹ۿ</a>| <a href="http://hbtelong.com" target="_blank">˳77777ɫ߲</a>| <a href="http://2266511.com" target="_blank">sihuƷ</a>| <a href="http://52xdc.com" target="_blank">޾Ʒa߹ۿ</a>| <a href="http://www33399.com" target="_blank">VƬ߹ۿ</a>| <a href="http://hezuoedu.com" target="_blank">ѹҹ</a>| <a href="http://fsbj168.com" target="_blank">Ƶ߲Ŵȫ</a>| <a href="http://8mav938.com" target="_blank">jizzjizzƵѿ</a>| <a href="http://juguanghr.com" target="_blank">㽶Ʒþ </a>| <a href="http://yiqigxfc.com" target="_blank">޳AVƬһ</a>| <a href="http://kph37.com" target="_blank">AVƬ߹ۿ</a>| <a href="http://jujiamy.com" target="_blank">AVƷɫ </a>| <a href="http://57gt.com" target="_blank">һվ</a>| <a href="http://4388x4.com" target="_blank">þ99žŹѿС˵</a>| <a href="http://9xav.com" target="_blank">һ֮</a>| <a href="http://bjfljg.com" target="_blank">ٸһ˳</a>| <a href="http://laosanqq.com" target="_blank">޾Ʒҹvaþ</a>| <a href="http://54vpn.com" target="_blank">߲ѲavƬ</a>| <a href="http://avdaka.com" target="_blank">Ծ޾ƷAAƬ߲ </a>| <a href="http://kssijia.com" target="_blank">þþƷӰѶ</a>| <a href="http://wwwkk2347.com" target="_blank">99Ļ </a>| <a href="http://nh-car.com" target="_blank">޳AƬ77777</a>| <a href="http://0354888.com" target="_blank">ŮˬˬˬƵ </a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>