Antwort
 
Themen-Optionen
Alt 25.06.2005, 23:24 Nach oben    #1
cyberdevil87
Gast
 
Beiträge: n/a
Standard Datei einlesen.

Hi haba folgendes prob ich möchte das eine TXT datei aus C:\test.txt eingelesen wird und geändert. Habe aber keine ahnung wie ich die datei einlesen kann soweit bin ich erstmal:

class ReplaceDemo
{
public static String replace( String s, String search, String replace )
{
int start = 0, pos = 0;
StringBuffer result = new StringBuffer( s.length() );
while ( (pos = s.indexOf(search, start)) >= 0 )
{
result.append( s.substring(start, pos) );
result.append( replace );
start = pos + search.length();
}
result.append( s.substring(start) );

return result.toString();
}

public static void main( String args[] )
{
String s1 = "Meine datei!!";
String s2 = replace(s1, "a", ".0.");
String s3 = replace(s2, "b", ".00.");
String s4 = replace(s3, "c", ".000.");
String s5 = replace(s4, "d", ".0000.");
String s6 = replace(s5, "e", ".5.");
String s7 = replace(s6, "f", ".6.");
String s8 = replace(s7, "g", ".7.");
String s9 = replace(s8, "h", ".8.");
String s10 = replace(s9, "i", ".9.");
String s11 = replace(s10, "j", ".10.");
String s12 = replace(s11, "k", ".11.");
String s13 = replace(s12, "l", ".12.");
String s14 = replace(s13, "m", ".13.");
String s15 = replace(s14, "n", ".14.");
String s16 = replace(s15, "o", ".15.");
String s17 = replace(s16, "p", ".16.");
String s18 = replace(s17, "q", ".17.");
String s19 = replace(s18, "r", ".18.");
String s20 = replace(s19, "s", ".19.");
String s21 = replace(s20, "t", ".20.");
String s22 = replace(s21, "u", ".21.");
String s23 = replace(s22, "v", ".22.");
String s24 = replace(s23, "w", ".23.");
String s25 = replace(s24, "x", ".24.");
String s26 = replace(s25, "y", ".25.");
String s27 = replace(s26, "z", ".26.");
String s28 = replace(s27, "A", ".27.");
String s29 = replace(s28, "B", ".28.");
String s30 = replace(s29, "C", ".29.");
String s31 = replace(s30, "D", ".30.");
String s32 = replace(s31, "E", ".31.");
String s33 = replace(s32, "F", ".32.");
String s34 = replace(s33, "G", ".33.");
String s35 = replace(s34, "H", ".34.");
String s36 = replace(s35, "I", ".35.");
String s37 = replace(s36, "J", ".36.");
String s38 = replace(s37, "K", ".37.");
String s39 = replace(s38, "L", ".38.");
String s40 = replace(s39, "M", ".39.");
String s41 = replace(s40, "N", ".40.");
String s42 = replace(s41, "O", ".41.");
String s43 = replace(s42, "P", ".42.");
String s44 = replace(s43, "Q", ".43.");
String s45 = replace(s44, "R", ".44.");
String s46 = replace(s45, "S", ".45.");
String s47 = replace(s46, "T", ".46.");
String s48 = replace(s47, "U", ".47.");
String s49 = replace(s48, "V", ".48.");
String s50 = replace(s49, "W", ".49.");
String s51 = replace(s50, "X", ".50.");
String s52 = replace(s51, "Y", ".51.");
String s53 = replace(s52, "Z", ".53.");
String s54 = replace(s53, "1", ".54.");
String s55 = replace(s54, "2", ".55.");
String s56 = replace(s55, "3", ".56.");
String s57 = replace(s56, "4", ".57.");
String s58 = replace(s57, "5", ".58.");
String s59 = replace(s58, "6", ".59.");
String s60 = replace(s59, "7", ".60.");
String s61 = replace(s60, "8", ".61.");
String s62 = replace(s61, "9", ".62.");
String s63 = replace(s62, "!", ".63.");
String s64 = replace(s63, "µ", ".64.");
String s65 = replace(s64, "§", ".65.");
String s66 = replace(s65, "$", ".66.");
String s67 = replace(s66, "%", ".67.");
String s68 = replace(s67, "&", ".68.");
String s69 = replace(s68, "/", ".69.");
String s70 = replace(s69, "(", ".70.");
String s71 = replace(s70, ")", ".71.");
String s72 = replace(s71, "=", ".72.");
String s73 = replace(s72, "?", ".73.");
String s74 = replace(s73, "ß", ".74.");
String s75 = replace(s74, "²", ".75.");
String s76 = replace(s75, "³", ".76.");
String s77 = replace(s76, "{", ".77.");
String s78 = replace(s77, "[", ".78.");
String s79 = replace(s78, "]", ".79.");
String s80 = replace(s79, "}", ".80.");
String s81 = replace(s80, " ", ".01010.");
try{
Thread.sleep(2000);
}catch(InterruptedException e){}
System.out.print(s81);

}
}

Wie könnte es denn aussehen?
 
Add Post to del.icio.usBookmark Post in TechnoratiDiesen Beitrag zu Mister Wong hinzufügen!
Mit Zitat antworten
Alt 26.06.2005, 19:50 Nach oben    #2
Erfahrener Benutzer
 
Benutzerbild von Gottzilla
 
Registriert seit: 02.02.2005
Beiträge: 524
Standard

Schau dir mal in der API den BufferedReader fürs lesen und den BufferedWriter fürs schreiben an

Beispiel fürs lesen deiner Datei:

PHP-Code:
 try {
   
String temp null;
   
StringBuffer text = new StringBuffer();
   
BufferedReader buff = new BufferedReader(new FileReader("C:/test.txt"));
   while ((
temp buff.readLine()) != null) {
      
text.append(temp System.getProperty("line.separator"));
   }
   
buff.close();
}
catch (
IOException e) {
   
System.out.println(e);

kann kleine Fehler (wie ; vergessen oder so ) enthalten, da ich das jetzt schnell zusammengebastelt hab.
Gottzilla ist offline  
Add Post to del.icio.usBookmark Post in TechnoratiDiesen Beitrag zu Mister Wong hinzufügen!
Mit Zitat antworten
Alt 26.06.2005, 20:29 Nach oben    #3
cyberdevil87
Gast
 
Beiträge: n/a
Standard

Danke für deine Schnelle antwort werde es mal testen.
 
Add Post to del.icio.usBookmark Post in TechnoratiDiesen Beitrag zu Mister Wong hinzufügen!
Mit Zitat antworten
Alt 27.06.2005, 09:22 Nach oben    #4
Erfahrener Benutzer
 
Benutzerbild von Gottzilla
 
Registriert seit: 02.02.2005
Beiträge: 524
Standard

naja, so schnell war die antwort auch wieder nicht . Wenn de Fragen hast, dann frag einfach
Gottzilla ist offline  
Add Post to del.icio.usBookmark Post in TechnoratiDiesen Beitrag zu Mister Wong hinzufügen!
Mit Zitat antworten
Antwort

Lesezeichen


Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 
Themen-Optionen

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
Sql Datei einlesen? heohni PHP-Programmierung 5 01.10.2006 19:16
Textdatei einlesen geht nur halb?! Steve231 Datenbanken 4 08.11.2005 09:28
Datei einlesen XmX Desktop-Applikationen und Grafik 7 11.05.2005 21:17
Textausgabe in Datei obiwankenobi Allgemeine Java-Programmierung 2 09.05.2005 12:51
Java findet Datei nicht Niki_Tesla Allgemeine Java-Programmierung 14 14.12.2004 22:31


Alle Zeitangaben in WEZ +2. Es ist jetzt 05:27 Uhr.


Powered by vBulletin® Version 3.7.3 (Deutsch)
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44