javawriteto的简单介绍
本篇文章给大家谈谈javawriteto,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
java怎样将大写字母转换成小写字母
1、具体代码如下,字符串中大、小写互转
1)输入
第一行只有一个整数m(m=10),表示测试数据组数。
接下来的m行,每行有一个字符串(长度不超过100)。
2)输出
输出互换后的字符串,每组输出占一行。
输入字符串,字符串可以求出字符串的长度以及在各个索引的值,Java也有专门的判断是不是大小写以及转换成大小写的方法
输出结果:如下图
扩展资料:
java中把一个字符串中大写字母转换为小写,小写字母转换为大写的思路
但是需要注意的是如果某个字符串定义为String类型,那么这个串就不能改变了,如果需要改变,那么应该使用StringBuffer
代码中exChange()能够得到正确的结论,exChange2()不能得到正确的结论,如果某个字符串定义为String类型,那么这个串就不能改变了
java 按行读取txt文件的数字
可以通过Java的IO流实现txt文本的读取,然后用readline实现按行读取。具体代码如下:
package test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Test {
public static double[] writeToDat(String path) {
File file = new File(path);
List list = new ArrayList();
double[] nums = null;
try {
BufferedReader bw = new BufferedReader(new FileReader(file));
String line = null;
//因为不知道有几行数据,所以先存入list集合中
while((line = bw.readLine()) != null){
list.add(line);
}
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
//确定数组长度
nums = new double[list.size()];
for(int i=0;ilist.size();i++){
String s = (String) list.get(i);
nums[i] = Double.parseDouble(s);
}
return nums;
}
public static void main(String[] args) {
String path = "d:/file4.txt";
double[] nums = writeToDat(path);
for(int i=0;inums.length;i++){
System.out.println(nums[i]);
}
}
}
JAVA文件追加的几种方式
java文件追加内容的三种方法:
方法一:
public static void writeToTxtByRandomAccessFile(File file, String str){
RandomAccessFile randomAccessFile = null;
try {
randomAccessFile = new RandomAccessFile(file,"rw");
long len = randomAccessFile.length();
randomAccessFile.seek(len);
randomAccessFile.writeBytes(new String(str.getBytes(),"iso8859-1")+"\r\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}finally{
try {
randomAccessFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
方法二:
public static void writeToTxtByFileWriter(File file, String content){
BufferedWriter bw = null;
try {
FileWriter fw = new FileWriter(file, true);
bw = new BufferedWriter(fw);
bw.write(content);
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
方法三:
public static void writeToTxtByOutputStream(File file, String content){
BufferedOutputStream bufferedOutputStream = null;
try {
bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file, true));
bufferedOutputStream.write(content.getBytes());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch(IOException e ){
e.printStackTrace();
}finally{
try {
bufferedOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
javawriteto的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、javawriteto的信息别忘了在本站进行查找喔。
发布于:2022-11-30,除非注明,否则均为
原创文章,转载请注明出处。