java小知识.docx
《java小知识.docx》由会员分享,可在线阅读,更多相关《java小知识.docx(16页珍藏版)》请在冰豆网上搜索。
![java小知识.docx](https://file1.bdocx.com/fileroot1/2023-1/8/23b4052a-7250-46bb-927b-ed697c0963b1/23b4052a-7250-46bb-927b-ed697c0963b11.gif)
java小知识
常见的返回类型可以分为2种:
1、基本数据类型
基本数据类型又可以分为3小类:
整型数据类型,布尔数据类型,浮点型数据类型
整型数据类型:
byte(1个字节)----字节型
short(2个字节)-----短整型
char(2个字节)----字符型
int(4个字节)----整型
long(8个字节)-----长整型
布尔类型:
boolean(1个字节)----布尔型
浮点型:
float(4个字节)----单精度浮点型
double(8个字节)----双精度浮点型
2、对象类型:
1)自定义的对象类型
2)类库类型
每一种返回类型都有默认值:
int:
0
byte:
0
char:
/u0000(在控制台显示为一个方格)
short:
0
long:
0
boolean:
false
float:
0.0
Double:
0.0
Object:
null
java自定义文件操作类实例代码
2010-09-2008:
45:
04 我来说两句
收藏
我要投稿
1.packagecn.edu.tongji.cims.wade.system;
2.importjava.io.*;
3.
4.publicclassFileOperate{
5.publicFileOperate(){
6.}
7.
8./**
9.*新建目录
10.*@paramfolderPathString如c:
/fqf
11.*@returnboolean
12.*/
13.publicvoidnewFolder(StringfolderPath){
14.try{
15.StringfilePath=folderPath;
16.filePath=filePath.toString();
17.java.io.FilemyFilePath=newjava.io.File(filePath);
18.if(!
myFilePath.exists()){
19.myFilePath.mkdir();
20.}
21.}
22.catch(Exceptione){
23.System.out.println("新建目录操作出错");
24.e.printStackTrace();
25.}
26.}
27.
28./**
29.*新建文件
30.*@paramfilePathAndNameString文件路径及名称如c:
/fqf.txt
31.*@paramfileContentString文件内容
32.*@returnboolean
33.*/
34.publicvoidnewFile(StringfilePathAndName,StringfileContent){
35.
36.try{
37.StringfilePath=filePathAndName;
38.filePath=filePath.toString();
39.FilemyFilePath=newFile(filePath);
40.if(!
myFilePath.exists()){
41.myFilePath.createNewFile();
42.}
43.FileWriterresultFile=newFileWriter(myFilePath);
44.PrintWritermyFile=newPrintWriter(resultFile);
45.StringstrContent=fileContent;
46.myFile.println(strContent);
47.resultFile.close();
48.}
49.catch(Exceptione){
50.System.out.println("新建目录操作出错");
51.e.printStackTrace();
52.}
53.
54.}
55.
56./**
57.*删除文件
58.*@paramfilePathAndNameString文件路径及名称如c:
/fqf.txt
59.*@paramfileContentString
60.*@returnboolean
61.*/
62.publicvoiddelFile(StringfilePathAndName){
63.try{
64.StringfilePath=filePathAndName;
65.filePath=filePath.toString();
66.java.io.FilemyDelFile=newjava.io.File(filePath);
67.myDelFile.delete();
68.
69.}
70.catch(Exceptione){
71.System.out.println("删除文件操作出错");
72.e.printStackTrace();
73.}
74.}
75.
76./**
77.*删除文件夹
78.*@paramfilePathAndNameString文件夹路径及名称如c:
/fqf
79.*@paramfileContentString
80.*@returnboolean
81.*/
82.publicvoiddelFolder(StringfolderPath){
83.try{
84.delAllFile(folderPath);//删除完里面所有内容
85.StringfilePath=folderPath;
86.filePath=filePath.toString();
87.java.io.FilemyFilePath=newjava.io.File(filePath);
88.myFilePath.delete();//删除空文件夹
89.}
90.catch(Exceptione){
91.System.out.println("删除文件夹操作出错");
92.e.printStackTrace();
93.}
94.}
95.
96./**
97.*删除文件夹里面的所有文件
98.*@parampathString文件夹路径如c:
/fqf
99.*/
100.publicvoiddelAllFile(Stringpath){
101.Filefile=newFile(path);
102.if(!
file.exists()){
103.return;
104.}
105.if(!
file.isDirectory()){
106.return;
107.}
108.String[]tempList=file.list();
109.Filetemp=null;
110.for(inti=0;i111.if(path.endsWith(File.separator)){
112.temp=newFile(pathtempList[i]);
113.}
114.else{
115.temp=newFile(pathFile.separatortempList[i]);
116.}
117.if(temp.isFile()){
118.temp.delete();
119.}
120.if(temp.isDirectory()){
121.delAllFile(path"/"tempList[i]);//先删除文件夹里面的文件
122.delFolder(path"/"tempList[i]);//再删除空文件夹
123.}
124.}
125.}
126.
127./**
128.*复制单个文件
129.*@paramoldPathString原文件路径如:
c:
/fqf.txt
130.*@paramnewPathString复制后路径如:
f:
/fqf.txt
131.*@returnboolean
132.*/
133.publicvoidcopyFile(StringoldPath,StringnewPath){
134.try{
135.intbytesum=0;
136.intbyteread=0;
137.Fileoldfile=newFile(oldPath);
138.if(oldfile.exists()){//文件存在时
139.InputStreaminStream=newFileInputStream(oldPath);//读入原文件
140.FileOutputStreamfs=newFileOutputStream(newPath);
141.byte[]buffer=newbyte[1444];
142.intlength;
143.while((byteread=inStream.read(buffer))!
=-1){
144.bytesum=byteread;//字节数文件大小
145.System.out.println(bytesum);
146.fs.write(buffer,0,byteread);
147.}
148.inStream.close();
149.}
150.}
151.catch(Exceptione){
152.System.out.println("复制单个文件操作出错");
153.e.printStackTrace();
154.}
155.}
156.
157./**
158.*复制整个文件夹内容
159.*@paramoldPathString原文件路径如:
c:
/fqf
160.*@paramnewPathString复制后路径如:
f:
/fqf/ff
161.*@returnboolean
162.*/
163.publicvoidcopyFolder(StringoldPath,StringnewPath){
164.
165.try{
166.(newFile(newPath)).mkdirs();//如果文件夹不存在则建立新文件夹
167.Filea=newFile(oldPath);
168.String[]file=a.list();
169.Filetemp=null;
170.for(inti=0;i171.if(oldPath.endsWith(File.separator)){
172.temp=newFile(oldPathfile[i]);
173.}
174.else{
175.temp=newFile(oldPathFile.separatorfile[i]);
176.}
177.
178.if(temp.isFile()){
179.FileInputStreaminput=newFileInputStream(temp);
180.FileOutputStreamoutput=newFileOutputStream(newPath"/"
181.(temp.getName()).toString());
182.byte[]b=newbyte[1024*5];
183.intlen;
184.while((len=input.read(b))!
=-1){
185.output.write(b,0,len);
186.}
187.output.flush();
188.output.close();
189.input.close();
190.}
191.if(temp.isDirectory()){//如果是子文件夹
192.copyFolder(oldPath"/"file[i],newPath"/"file[i]);
193.}
194.}
195.}
196.catch(Exceptione){
197.System.out.println("复制整个文件夹内容操作出错");
198.e.printStackTrace();
199.}
200.
201.}
202.
203./**
204.*移动文件到指定目录
205.*@paramoldPathString如:
c:
/fqf.txt
206.*@paramnewPathString如:
d:
/fqf.txt
207.*/
208.publicvoidmoveFile(StringoldPath,StringnewPath){
209.copyFile(oldPath,newPath);
210.delFile(oldPath);
211.
212.}
213.
214./**
215.*移动文件到指定目录
216.*@paramoldPathString如:
c:
/fqf.txt
217.*@paramnewPathString如:
d:
/fqf.txt
218.*/
219.publicvoidmoveFolder(StringoldPath,StringnewPath){
220.copyFolder(oldPath,newPath);
221.delFolder(oldPath);
222.
223.}
224.}
告:
博客新增直接引用代码功能 专访李铁军:
从医生到金山首席安全专家的转变 CSDN博客频道自定义域名、标签搜索功能上线啦!
独一无二的职位:
开源社区经理
前端常用的获取参数的方法
2012-07-2015:
5450人阅读评论(0)收藏举报
url服务器
目录(?
)[-]
1.BasePath
2.获取应用服务名
BasePath
StringbasePath=request.getScheme()+":
//"+request.getServerName()+":
"+request.getServerPort();
这其实就是获得应用的根url,比如说你的应用的根路径是http:
//localhost:
8080,那么你列出的代码就是为basePath赋值为http:
//localhost:
8080。
1、request.getScheme()返回协议的名称 http,和后面的":
//"拼起来就成了http:
//
2、request.getServerName()这是获取你的服务器的名称,如果你的应用部署在本机那么其就返回localhost或者127.0.0.1,这2个是等价的
3、request.getServerPort() 是你应用使用的端口,比如8080或者80 等等 上面3点的结果拼起来就构成了你应用的根路径或者说是根url
获取应用服务名
${pageContext.request.contextPath}”的作用是取出部署的应用程序名,这样不管如何部署,所用路径都是正确的。
struts中关于Json的配置
2012-07-1911:
28391人阅读评论(0)收藏举报
jsonstrutsinterceptorclass编程
....
以上为常规编程中JSON的配置,但是疑惑是其extends的名字json-default可否置换?
json-default其实也是最终继承struts-default的json-plugn中struts-plugn.xml源码如下:
这里你可以看到这个json-default是干了什么事情,无非就是:
1加了个名为json的result类型2加了一层名为json的拦截器所以
对于此类问题,可以说不继承json-default ,可以,但是你必须在你的struts.xml中添加一个resultType也就是在你的struts.xml的节点下添加以下内容:
----这里的name就按照你喜欢的取了也就是你的第二个问题^^然后在你配置的拦截器声明中加上 也就是json拦截器的声明,接下来再在你的default-stack-ref(或者其他拦截器引用的地方)引用这个名字为json的拦截器就可以了
[教程]两台笔记本无线共享上网
分类:
程序人生2011-07-2617:
55134人阅读评论(0)收藏举报
网络dns服务器internetdllwindows加密
家里有两台笔记本,一个宽带网端口,一条网线,如何实现两台笔记本同时上网?
下面就介绍一种笔记本无线共享上网的方法,具体步骤如下(以下为XP系统下的设置,Vista设置程序与此类似)。
首先,选择其中一台笔记本当做主机。
打开主机的“网络连接”,选择“无线网络连接”,右键打开属性对话框,在“常规”选项卡下,双击“TCP/IP协议”。
配置IP地址和子网掩码分别为192.168.0.1和255.255.255.0(如图),其他的不需要设置,如显示与宽带IP冲突时,请重新启动计算机后再试。
然后,再点击主机的“无线网络连接属性”窗口的“无线网络配置”,选中“用windows配置我的无线网络设置”,点击下方的“高级”,在要访问的网络里,勾上“仅计算机到计算机(待定)”,不要勾选“自动连接到非首选的网络”。
如图:
建立一个无线虚拟AP,这步是关键。
在主机“无线网络配置”选项卡里,首选网络下,点击“添加”,为主机添加一个SSID:
自定义网络名为“dll”,网络验证:
开放式,数据加密:
WEB,网络密钥:
可以输入5或13位ASCII字符或10或26位十六进制字符,不要勾选“自动为我提供此密钥。
也可不设置密钥,但出于无线局域网的安全考虑,一般不建议进行此操作
配置主机“宽带连接属性”中的“高级”选项卡。
勾选“允许其他用户通过此计算机的Internet来连接”和“每当网络上的计算机试图访问Internet时建立一个拨号连接”。
分机设置十分简单。
重复步骤一,设置“TCP/IP协议属性“,为”自动获得IP地址“和”自动获得DNS服务器地址“。
点击”确定“。
鼠标右键点击“无线网络连接”,选择“查看可用的无线连接”,搜索到刚才新建的无线网络“dll”,点击连接(主机和分机执行相同的动作),则无线局域共享设置成功。
这个时候我们在每台计算机上查看右下角的无线图标就会发现显示的是“无线网络连接,速度54Mbps,信号强度非常好,状态已连接上”。
两台笔记本就可以同时上网了。