新聞中心
用java寫代碼,從TXT中按行讀取數(shù)據(jù),遇到指定的字符時,輸出后面的第二個數(shù)值,怎么寫,求大神。。。
package com.test;

從網(wǎng)站建設(shè)到定制行業(yè)解決方案,為提供成都網(wǎng)站設(shè)計、網(wǎng)站建設(shè)服務(wù)體系,各種行業(yè)企業(yè)客戶提供網(wǎng)站建設(shè)解決方案,助力業(yè)務(wù)快速發(fā)展。成都創(chuàng)新互聯(lián)公司將不斷加快創(chuàng)新步伐,提供優(yōu)質(zhì)的建站服務(wù)。
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Test {
public static void main(String[] args) {
getString(';');
}
public static void getString(char ch) {
FileInputStream inputStream = null;
try {
StringBuffer buffer = new StringBuffer();
inputStream = new FileInputStream(new File("D:\\test.txt"));
int i = 0;
while (i != -1) {
i = inputStream.read();
if ((char) i != ch) {
buffer.append((char) i);
} else {
System.out.println(buffer.toString());
buffer.setLength(0);
}
}
if (i == -1) {
System.out.println(buffer.toString());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
給段最簡單的java代碼 讓我新手看一下
最簡單的java代碼肯定就是這個了,如下:
public class MyFirstApp
{
public static void main(String[] args)
{
System.out.print("Hello world");
}
}
“hello world”就是應(yīng)該是所有學(xué)java的新手看的第一個代碼了。如果是零基礎(chǔ)的新手朋友們可以來我們的java實(shí)驗班試聽,有免費(fèi)的試聽課程幫助學(xué)習(xí)java必備基礎(chǔ)知識,有助教老師為零基礎(chǔ)的人提供個人學(xué)習(xí)方案,學(xué)習(xí)完成后有考評團(tuán)進(jìn)行專業(yè)測試,幫助測評學(xué)員是否適合繼續(xù)學(xué)習(xí)java,15天內(nèi)免費(fèi)幫助來報名體驗實(shí)驗班的新手快速入門java,更好的學(xué)習(xí)java!
請問用java創(chuàng)建一個TXT文件,文件里寫“你好”,代碼怎么寫
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
public class Io{
public static void main(String [] s){
File filename = new File("F:\\suncity.txt");
String filein="你好!";
RandomAccessFile mm = null;
try {
mm = new RandomAccessFile(filename,"rw");
mm.writeBytes(filein);
} catch (IOException e1) {
// TODO 自動生成 catch 塊
e1.printStackTrace();
} finally{
if(mm!=null){
try {
mm.close();
} catch (IOException e2) {
// TODO 自動生成 catch 塊
e2.printStackTrace();
}
}
}
}
}
分享題目:java初級代碼txt的簡單介紹
文章起源:http://fisionsoft.com.cn/article/ddcjseg.html


咨詢
建站咨詢
