我使用BufferedReader
来读取普通的txt文件。您可以在此代码中看到txt文件的底部。
我的代码:
FileInputStream fIn = new FileInputStream(myFilee);
BufferedReader myReader = new
BufferedReader(new InputStreamReader(fIn));
String aDataRow = "";
String aBuffer = "";
while ((aDataRow = myReader.readLine()) != null) {
aBuffer += aDataRow + "\n";
Log.e("mcpeturkk","buffer: "+aBuffer);
}
我的文字文件:
mp_username:Heroatabrk
game_difficulty_new:1
game_thirdperson:0
gfx_dpadscale:0.5
mp_server_visible:1
mp_xboxlive_visible:1
game_flatworldlayers:[7,3,3,2]
game_limitworldsize:0
game_language:tr_TR
game_skintypefull:Standard_Steve
game_lastcustomskinnew:
game_recentskin1:
game_recentskin2:
game_recentskin3:
game_automationserverretrytime:30
game_haseverloggedintoxbl:0
game_haschosennottosignintoxbl:1
ctrl_sensitivity:0.55
ctrl_invertmouse:0
ctrl_islefthanded:0
ctrl_usetouchscreen:0
ctrl_usetouchjoypad:0
ctrl_swapjumpandsneak:0
feedback_vibration:1
ctrl_autojump:1
gfx_renderdistance_new:128
gfx_particleviewdistance:0
gfx_viewbobbing:1
gfx_fancygraphics:1
gfx_transparentleaves:1
gfx_fancyskies:1
gfx_hidegui:0
gfx_field_of_view:70
gfx_msaa:1
gfx_texel_aa_2:0
gfx_gamma:0
gfx_fullscreen:0
gfx_guiscale_offset:0
audio_sound:1
audio_music:1
vr_sensitivity:0.5
vr_gamma:0
vr_particle_view_dist:0.25
vr_stutter_turn:1
vr_hide_gui:0
vr_stutter_turn_sound:1
vr_hmd_displacement:0
vr_renderdistance:128
vr_autojump:1
vr_head_steering:1
vr_stutter_turn_constant_time:1
vr_stereorendering:1
vr_hud_at_top:0
vr_use_normal_hit:0
vr_use_red_flash:1
vr_rstick_pitch_assist:0
vr_rstick_gazeadjust:0
vr_gaze_pitch_boost:1
vr_hud_drift:1
vr_living_room_cursor_centered:1
vr_linear_jump:1
vr_linear_motion:1
vr_sticky_mining:1
vr_tap_turn:0
vr_tapturn_sensitivity:0.375
vr_wheelturn_sensitivity:0.6
vr_wheelturning_withLowDeadzone_controller:0
vr_180_turns:0
vr_use_comfort_controls_2:1
vr_show_comfort_select_screen:1
vr_livingroom_hint_time:32000
vr_mirror_texture:1
vr_ui_mouse_sensitivity:1
vr_msaa:2
dev_autoloadlevel:0
dev_showchunkmap:105
dev_disablefilesystem:0
dev_enable_profiler:0
dev_uselocalserver:0
dev_connection_quality:0
old_game_version_major:0
old_game_version_minor:16
old_game_version_patch:0
old_game_version_beta:0
realms_show_friend_invites_only:111
allow_cellular_data:1
ctrl_sensitivity_mouse:0.33
ctrl_sensitivity_touch:0.55
ctrl_sensitivity_gamepad:0.33
ctrl_invertmouse_mouse:0
ctrl_invertmouse_touch:0
ctrl_invertmouse_gamepad:0
ctrl_autojump_mouse:1
ctrl_autojump_touch:1
ctrl_autojump_gamepad:1
feedback_vibration_mouse:1
feedback_vibration_touch:1
feedback_vibration_gamepad:1
ctrl_togglecrouch_mouse:0
ctrl_togglecrouch_touch:1
ctrl_togglecrouch_gamepad:0
ctrl_type_0_key.jump:1
ctrl_type_0_key.drop:6
ctrl_type_0_key.attack:-99
ctrl_type_0_key.use:-100
ctrl_type_0_container.crafting:3
ctrl_type_0_key.inventory:4
ctrl_type_0_key.cycleItemLeft:11
ctrl_type_0_key.cycleItemRight:12
ctrl_type_0_key.togglePerspective:9
ctrl_type_0_key.sneak:2
ctrl_type_0_key.pause:14
ctrl_type_0_key.flyUpSlow:0
ctrl_type_0_key.flyDownSlow:10
ctrl_type_0_key.mobEffects:7
ctrl_type_0_key.chat:8
ctrl_type_0_key.left:0
ctrl_type_0_key.right:0
ctrl_type_0_key.back:0
ctrl_type_0_key.forward:0
ctrl_type_0_key.interactwithtoast:13
ctrl_type_1_key.jump:1
ctrl_type_1_key.drop:6
ctrl_type_1_key.attack:12
ctrl_type_1_key.use:11
ctrl_type_1_container.crafting:3
ctrl_type_1_key.inventory:4
ctrl_type_1_key.cycleItemLeft:7
ctrl_type_1_key.cycleItemRight:8
ctrl_type_1_key.togglePerspective:9
ctrl_type_1_key.sneak:2
ctrl_type_1_key.pause:14
ctrl_type_1_key.flyUpSlow:0
ctrl_type_1_key.flyDownSlow:10
ctrl_type_1_key.mobEffects:0
ctrl_type_1_key.chat:5
ctrl_type_1_key.left:0
ctrl_type_1_key.right:0
ctrl_type_1_key.back:0
ctrl_type_1_key.forward:0
ctrl_type_1_key.interactwithtoast:13
ctrl_type_2_key.jump:1
ctrl_type_2_key.drop:6
ctrl_type_2_key.attack:-99
ctrl_type_2_key.use:-100
ctrl_type_2_container.crafting:3
ctrl_type_2_key.inventory:4
ctrl_type_2_key.cycleItemLeft:11
ctrl_type_2_key.cycleItemRight:12
ctrl_type_2_key.togglePerspective:9
ctrl_type_2_key.sneak:2
ctrl_type_2_key.pause:14
ctrl_type_2_key.flyUpSlow:0
ctrl_type_2_key.flyDownSlow:10
ctrl_type_2_key.mobEffects:7
ctrl_type_2_key.chat:8
ctrl_type_2_key.left:0
ctrl_type_2_key.right:0
ctrl_type_2_key.back:0
ctrl_type_2_key.forward:0
ctrl_type_2_key.interactwithtoast:13
key_key.attack:-99
key_key.pickItem:-97
key_key.use:-98
key_key.drop:81
key_key.hotbar.1:49
key_key.hotbar.2:50
key_key.hotbar.3:51
key_key.hotbar.4:52
key_key.hotbar.5:53
key_key.hotbar.6:54
key_key.hotbar.7:55
key_key.hotbar.8:56
key_key.hotbar.9:57
key_key.inventory:69
key_key.togglePerspective:116
key_key.jump:32
key_key.sneak:16
key_key.sprint:17
key_key.left:65
key_key.right:68
key_key.back:83
key_key.forward:87
key_key.mobEffects:90
key_key.chat:84,13
key_key.command:191
但它会读到(正如我在logcat上看到的)key_key.hotbar.2:50
key_key.h//2
。这行之后不读。我希望它不是一个重复的帖子,因为ı用力搜索。
答案 0 :(得分:0)
如果是java 8
,可以使用以下方法FileInputStream inputStream = new FileInputStream("yourfile.txt");
try
{
String data = IOUtils.toString(inputStream);
}
finally
{
inputStream.close();
}
只是你可以使用scanner而不是BufferedReader
Scanner in = new Scanner(new FileReader("yourfile.txt"));
String line , data = "";
line = in.nextLine();
while(line!=null)
{
data += line + "\n";
line=in.nextLine();
}
//data contains all the file may b really all the file you need to read