请哪位朋友给我写几个简单的例子
一. 把一个字符串中的大写字母变成相应的小写字母(我写了一天总出错,找不到原因想求完整版)
二. 有个字符串abc,def,kkl;d;abc,ddf,把其中同abc相同的字符串去掉,把分号用,号代替。
三. 实现文件的复制与合并本人希望哪位大哥大姐帮帮小第,我都冒汗了,我不会给分,我有200可全给你们,谢谢了
一. 把一个字符串中的大写字母变成相应的小写字母(我写了一天总出错,找不到原因想求完整版)
二. 有个字符串abc,def,kkl;d;abc,ddf,把其中同abc相同的字符串去掉,把分号用,号代替。
三. 实现文件的复制与合并本人希望哪位大哥大姐帮帮小第,我都冒汗了,我不会给分,我有200可全给你们,谢谢了
解决方案 »
- java mysql PreparedStatement中文参数传递出现的问题
- 在struts1里怎么配置spring插件!!在srping里怎么配置
- 高手们,帮个忙吧!
- 使用Mina2时,能否将IoSession存放到Memcached中
- 一个关于 线程控制的问题!!!!请教大家 70分 就剩这些了!!
- 关于JFRAME中的文本框
- Question???????
- 请问POPUPMENU怎么加图片选项,在awt下
- applet中如何把TextField的值赋给char类型的变量?
- 高手求解答Android中Activity.this问题!!!
- 为什么我在import javax.servlet.*;的时候会出现错误
- 问一个有关public的问题
第一条写成
public class xx { public static void main(String[] args) {
String str =null;
String str1=null;
str="ABcDEFG";
str1=str.toLowerCase();
System.out.println(str1);
}
}
String a = "abc,def,kkl;d;abc,ddf,";
String b = a.replace("abc", "").replace(',', '.');
System.out.println(b);给分点管理就可以了
2.使用String.replace(char oldChar, char newChar)
3.使用java.io.*包中的类,java examples这本书就有例子完全满足你的需要,你用google搜吧。
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;/**
* @author Administrator
*
*/
public class CopyFile
{
public void copy(String srcFile, String dstFile) throws FileNotFoundException, IOException
{
BufferedReader br = new BufferedReader(new FileReader(srcFile));
StringBuffer sb = new StringBuffer();
String str = br.readLine();
while (str != null)
{
sb.append(str + "\n");
str = br.readLine();
}
br.close();
BufferedWriter bw = new BufferedWriter(new FileWriter(dstFile));
bw.write(sb.toString());
bw.close();
}
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
CopyFile cf = new CopyFile();
try{
cf.copy("e:\\test.txt", "e:\\test1.txt");
}catch (Exception e)
{
System.out.println(e.getMessage());
}
}}
自己再改一下就可以用了,不会说不知怎么改吧?
toLowerCase
public String toLowerCase()
Converts all of the characters in this String to lower case using the rules of the default locale. This is equivalent to calling toLowerCase(Locale.getDefault()).
Returns:
the String, converted to lowercase.
2
replace
public String replace(CharSequence target,
CharSequence replacement)
Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. The replacement proceeds from the beginning of the string to the end, for example, replacing "aa" with "b" in the string "aaa" will result in "ba" rather than "ab". Parameters:
target - The sequence of char values to be replaced
replacement - The replacement sequence of char values
Returns:
The resulting string 自己多查一下文档就好了 !
第二条就是字符替换,去掉第一个字符串中的abc,然后把“;”号用“,”号替代打出
2.replace("abc", "").replace(',', '.');
3.
while (str != null)
{
sb.append(str + "\n");
str = br.readLine();
}
br.close();
BufferedWriter bw = new BufferedWriter(new FileWriter(dstFile));
bw.write(sb.toString());
bw.close();
}
String a = "aBcD";
a = a.toLowerCase();//将字符串中的大写字符转换成小写
System.out.println(a);
String b = "abc,def,kkl;d;abc,ddf,";
b = b.replaceAll("abc","").replaceAll(";",",");////把字符串b其中和abc相同的字符串去掉,把字符串中的分号替换成逗号
System.out.println(b);
}
/**
* 拷贝文件
* @param toFile原文件
* @param fronFile目标文件
* @return 返回1表示拷贝成功,返回0则不成功
*/
public int toFile(String toFile,String fronFile){ try {
File fronF = new File(fronFile);
DataInputStream dis = new DataInputStream(new FileInputStream(fronF));
int read = dis.read();
FileOutputStream fqs = new FileOutputStream(toFile);
while (read != -1) {
fqs.write(read);
read = dis.read();
}
dis.close();
fqs.close();
}
catch (Exception e) {
System.out.println(e.toString());
return 0;
}
return 1;
}
"\n" -> "\r\n"
而且你做得每次都会在后面多加一个 回车~
并且 我觉得在.close()前先.flush()会更好一点~